It might be easier to see the pattern/algorithm for rotation if you use a different, array and (for now) don't think about the bit manipulation. Here's a 4 x 5:
Code:
a b c d e
f g h i j
k l m n o
p q r s t
Rotating 90 degrees clockwise gives
Code:
p k f a
q l g b
r m h c
s n i d
t o j e
So, you can see that for populating the new array, the top row (moving left to right) becomes the right column (moving top to bottom), the second row becomes the second-from-right column, etc. Assuming N rows and M columns in the original, you will then have M rows and N columns in the new array. Now, you need to find the pattern of mapping old coordinates to new. For example
Code:
a (0, 0) -> (0, 3)
b (0, 1) -> (1, 3)
c (0, 2) -> (2, 3)
d (0, 3) -> (3, 3)
e (0, 4) -> (4, 3)
...
l (2, 1) -> (1, 1)
m (2, 2) -> (2, 1)
n (2, 3) -> (3, 1)
...
q (3, 1) -> (1, 0)
r (3, 2) -> (2, 0)
s (3, 3) -> (3, 0)
t (3, 4) -> (4, 0)
Where coordinates are (old_row, old_col) -> (new_row, new_col)
If we say that the original matrix was N = 4 rows and M = 5 columns, the new matrix will be M rows (5) and N columns (4).
new_row is pretty easy, it just tracks the old_col. new_col is a bit trickier. It sort of tracks the old_row, but backwards. I'll let you figure that one out. You should express any formulae in terms of N and M instead of magic numbers like 4 or 5. You could apply similar logic for determining counter-clockwise rotations, or even 180 degree rotations.
The logic for doing this with bit manipulation is a bit trickier if you try to work it all into the loop, but you could create a function for storing a value in a particular bit location, the you just calculate new_row and new_col, and use your function to set the right bit:
Code:
value = get_bit(old_matrix, old_row, old_col);
new_row = old_col;
new_col = // you fill in this part
set_bit(new_matrix, new_row, new_col, value);
Hope that makes sense and helps you out.