Ctrl K

Flip the Bit Order

Easy
A sensor sends 32-bit words, but a firmware bug reverses the bit order of each word: the highest bit lands where the lowest should be and vice versa. You are given a non-negative integer x written with exactly 32 bits (leading zeros included). Reverse the order of those 32 bits and return the resulting number as an unsigned value.
Example 1
x=6 → 1610612736

6 is 000…0110 in 32 bits. Reversed it becomes 0110…000, i.e. bits 30 and 29: 2³⁰ + 2²⁹ = 1610612736.

Example 2
x=1 → 2147483648

The lowest bit moves to the very top: 2³¹ = 2147483648.

Example 3
x=4294967295 → 4294967295

All 32 bits are ones, so reversing changes nothing.

Constraints
  • 0 ≤ x < 2³²
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsCount the Set Bits EasyBoth Cases Stretch EasyK-th Largest Corner XOR MediumSum of Binary Strings EasyBalanced Tree from a Sorted List Easy
loading Python…
Input
x=6
Expected
1610612736

Run checks the first 3 tests in your browser. Submit checks all 9 tests on the server, hidden ones included.