top of page

Looking to master object-oriented and system design for tech interviews or career growth?

  • Improve your system design and machine coding skills.

  • Study with our helpful resources.

  • Prepare for technical interviews and advance your career.

**We're in beta mode and would love to hear your feedback.

Reverse Bits InterviewBit Solution

Problem: Reverse Bits

Problem Description

Reverse the bits of a 32-bit unsigned integer A.

Problem Constraints

0 <= A <= 232

Input Format

The first and only argument of input contains an integer A.

Output Format

Return a single unsigned integer denoting the decimal value of reversed bits.

Example Input

Input 1:
Input 2:

Example Output

Output 1:
Output 2:

Example Explanation

Explanation 1:

=>      00000000000000000000000000000000 

Explanation 2:

=>      11000000000000000000000000000000 

Solution Approach:

To solve this problem first find the positions of set bits in the original number then mirror those set bits according to that in your resultant variable.

That is for example if ith bit is a set bit in original number then set the (31-i)th bit of resultant number.

Solution in C++:


bottom of page