LeetCode OJ:Reverse Bits(旋转bit位)

时间:2023-02-07 05:00:20

Reverse bits of a given 32 bits unsigned integer.

For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as00111001011110000010100101000000).

注意应该做到平台无关性,需要做到这样的话应该声明一个uint32量然后一直向左移,知道得到 0 就可以得到uint32的位数大小 :

 class Solution {
public:
uint32_t reverseBits(uint32_t n) {
uint32_t result = ;
for(uint32_t i = ; i != ; i <<= ){
result <<= ;
result |= (n & );
n >>= ;
}
return result;
}
};