Blind 75
73 / 75Free practice

Reverse Bits

Easy · Bit manipulation

Jump to code

Reverse the order of all 32 bits in an unsigned 32-bit integer and return the resulting unsigned value. Leading zeros participate.

Examples

Example 1

n = 43261596

Output: 964176192

Example 2

n = 4294967293

Output: 3221225471

Constraints

  • 0 <= n <= 2^32 - 1; reverse all 32 bit positions, including leading zeros.
Need a hint?

Build the answer from the input’s least significant bit.

Real bit manipulation interview questions

Questions on the same topic that candidates reported from real company interviews. Some company questions are locked and open with Premium or XP.

Browse all real coding interview questions

Accepted submissions mark this problem complete. Progress stays in this browser.

Run checks 5 examples. Submit checks all 6 cases. A free account runs this problem; no XP needed.
Language
Case 1
Input
[
  43261596
]
Expected
964176192
Case 2
Input
[
  4294967293
]
Expected
3221225471
Case 3
Input
[
  0
]
Expected
0
Case 4
Input
[
  1
]
Expected
2147483648
Case 5
Input
[
  4294967295
]
Expected
4294967295

Drafts are saved per language in this browser when storage is available.