Reverse Bits
EasyBit Manipulation & Math
Decode it first. Clues, constraints, pattern and plan before any code.Treat n as an unsigned 32-bit integer and reverse the order of its 32 bits: bit 0 swaps with bit 31, bit 1 with bit 30, and so on. Return the result, also as an unsigned 32-bit value (between 0 and 2^32 - 1).
n = 43261596 → 964176192
00000010100101000001111010011100
→ 00111001011110000010100101000000
n = 1 → 2147483648 (only the top bit is set)
n = 4294967293 → 3221225471Constraints
0 <= n <= 2^32 - 1- Always reverse all 32 bits, including leading zeros.