ExamAdda Logo

Reverse Bits

Easy

Given a 32-bit unsigned integer n, reverse its binary representation and return the resulting unsigned integer.

For example, if the binary representation of n is:

00000010100101000001111010011100

 

after reversing all 32 bits, it becomes:

00111001011110000010100101000000

 

Return the decimal value represented by the reversed 32-bit binary number.

Example 1

Input

n = 43261596

Output

964176192

Explanation

The 32-bit binary representation of 43261596 is:

00000010100101000001111010011100

 

After reversing all 32 bits:

00111001011110000010100101000000

 

which represents:

964176192

Example 2

Input

n = 4294967293

Output

3221225471

Explanation

The 32-bit binary representation is:

11111111111111111111111111111101

 

After reversing all 32 bits:

10111111111111111111111111111111

 

which represents:

3221225471

Constraints

0 <= n <= 2^32 - 1
n is a 32-bit unsigned integer.
The binary representation must always be considered as exactly 32 bits
including leading zeros.

Hints:

Hint 1

Process all 32 bits one by one.

Hint 2

Extract the rightmost bit using:

n & 1

 

Then shift n to the right.

Author & Technical Reviewer

ExamAdda Technical Review Team

Technically reviewed by: ExamAdda Technical Review Team

Technical Reviewers, ExamAdda

Software engineers at ExamAdda who check every article's definitions, complexity claims and code examples before and after publishing.

Published

Aug 23, 2026

Last updated

Aug 23, 2026

Content Verification Methodology

Definitions and complexity claims were checked against authoritative computer-science references. Code examples were compiled and tested with standard, boundary and edge-case inputs.

Report a correction:editorial@examadda.org
Auto
Loading editor...
Input

Expected Output