Problem
You get an unsigned 32-bit integer n as a normal integer value. An unsigned 32-bit integer is a whole number from 0 to 2^32 - 1.
The binary form of a number uses only the digits 0 and 1. Each digit is a bit. Bit 0 is the rightmost bit, and bit 31 is the leftmost bit.
Write n in binary with exactly 32 bits, with zeros on the left when necessary. Reverse the order of the 32 bits. Return the value of the result as an unsigned integer.
Example 1
- Input:
- n = 1
- Output:
- 2147483648
- Explanation:
- Only bit 0 of 1 has the value 1. After you reverse the bits, only bit 31 is 1, so the result is
2^31.
Example 2
- Input:
- n = 6
- Output:
- 1610612736
- Explanation:
- In binary, 6 is
110, so bits 1 and 2 are 1. After you reverse the bits, bits 30 and 29 are 1, so the result is2^30 + 2^29.
Example 3
- Input:
- n = 4294967295
- Output:
- 4294967295
- Explanation:
- All 32 bits are 1, so the new order does not change the value.
Constraints
- 0 <= n <= 2^32 - 1
Follow-up
Suppose that a program calls the function many times. How can you make each call faster?
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 190. Reverse Bits
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source