Reverse bits of a given 32 bits unsigned integer.
For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as 00111001011110000010100101000000).
uint32_t reverseBits(uint32_t n) {
uint32_t value = n;
uint32_t result = 0;
int step = 31;
while (step>=0)
{
result |= (value&1)<<step;
value >>= 1;
step--;
}
return result;
}
本文介绍了一种算法,用于将给定的32位无符号整数的二进制位进行逆序处理。例如,输入43261596(二进制00000010100101000001111010011100),输出964176192(二进制00111001011110000010100101000000)。
861

被折叠的 条评论
为什么被折叠?



