Reverse Bits
Reverse the bits of a given 32-bit unsigned integer. Read the bits from least significant to most significant and emit them in the opposite order, returning the resulting 32-bit unsigned integer.
Open official problem prompt ↗Produce the integer whose 32-bit binary representation is the exact reverse of the input's.
Moving books off a shelf one at a time onto a new shelf; the first book you remove ends up at the far end, so the whole row comes out reversed.
- Input
- n = 43261596 (binary 00000010100101000001111010011100)
- Output
- 964176192 (binary 00111001011110000010100101000000)
- Why
- The 32-bit pattern read backwards is the reversed bit string, whose value is 964176192.
The input is a 32-bit unsigned integerBits are treated over exactly 32 positions