Rotate 2D grid of bits

38 Views Asked by At

I got this 64-bit value that I represent as an 8x8 grid with top-right = LSB and bottom-left = MSB:

0x20E0 = [
1 1 1 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
]

I want to rotate it 90° left or right:

// Rotated right.
0x30101  = [
0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 1
0 0 0 0 0 0 1 1
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0
]

There seem to be a lot of ways of doing this, but most of them seem rather costly to do. I want to rotate it to simplify the logic of something else in my code, but if it slows down my code to the point of affecting performance I won't use it.

Are there sources I can look at? I've had a hard time finding information for my particular use-case. Probably using the wrong search words.

0

There are 0 best solutions below