Bit reversal of an integer, ignoring integer size and endianness

后端 未结 12 2302
既然无缘
既然无缘 2021-01-03 00:18

Given an integer typedef:

typedef unsigned int TYPE;

or

typedef unsigned long TYPE;

I have the following

12条回答
  •  -上瘾入骨i
    2021-01-03 00:42

    The generic approach hat would work for objects of any type of any size would be to reverse the of bytes of the object, and the reverse the order of bits in each byte. In this case the bit-level algorithm is tied to a concrete number of bits (a byte), while the "variable" logic (with regard to size) is lifted to the level of whole bytes.

提交回复
热议问题