Rotating a bitmap 90 degrees

前端 未结 9 1918
粉色の甜心
粉色の甜心 2021-02-04 05:49

I have a one 64-bit integer, which I need to rotate 90 degrees in 8 x 8 area (preferably with straight bit-manipulation). I cannot figure out any handy algorith

9条回答
  •  忘掉有多难
    2021-02-04 06:32

    Without using any look-up tables, I can't see much better than treating each bit individually:

    unsigned long r = 0;
    for (int i = 0; i < 64; ++i) {
        r += ((x >> i) & 1) << (((i % 8) * 8) + (7 - i / 8));
    }
    

提交回复
热议问题