Reverse Bits
EasyP3Coding
Given a non-negative integer n, treat it as an unsigned 32-bit value, reverse the order of its 32 bits and return the result as an unsigned integer.
For example, the 32-bit pattern 00000000000000000000000000001011 becomes 11010000000000000000000000000000.
Example 1
- Input
- n = 43261596
- Output
- 964176192
- Why
- 43261596 is 00000010100101000001111010011100, reversed it is 00111001011110000010100101000000 = 964176192.
Example 2
- Input
- n = 4294967293
- Output
- 3221225471
Example 3
- Input
- n = 0
- Output
- 0
Constraints
- 0 <= n <= 2^32 - 1
Hints
Give it a real attempt first. Run shows which examples fail.
Saved automatically
Run checks the 3 visible tests, Submit all 10. ⌘Enter runs, ⌘⇧Enter submits.