Skip to content
BASA DSA

Reverse Bits

EasyBit Manipulation

Reverse the order of all 32 bits of unsigned integer n and return the result as an unsigned integer.

Example 1

Input
n = 1
Output
2147483648

Explanation

The lowest bit becomes the highest bit, yielding 2^31.

Example 2

Input
n = 4294967295
Output
4294967295

Explanation

All 32 one bits remain set when reversed.

Example 3

Input
n = 0
Output
0

Explanation

All 32 zero bits remain zero.

Example 4

Input
n = 2147483648
Output
1

Explanation

The highest bit becomes the lowest bit, yielding one.

Constraints

  • 0 <= n <= 4294967295

Function contractreverseBitsArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…