Topics requirements:
Reversed given 32-bit unsigned binary integer.
Example:
Input: 00000010100101000001111010011100
Output: 00111001011110000010100101000000
explained: 00000010100101000001111010011100 input binary string unsigned integer 43261596,
the flow returns 964,176,192, which is 00111001011110000010100101000000 binary representation.
Code:
class Solution {
public:
uint32_t reverseBits(uint32_t n) {
uint32_t result = 0;
for(int i = 0; i < 32; i++) {
result <<= 1;
result = result | (n & 1);
n >>= 1;
}
return result;
}
};
analysis:
Binary number will be assigned at the end of