Reverse Bits

Reverse the bits of a given 32-bit unsigned integer. Pattern focus: Set/Clear kth Bit. Read bits one by one and set them in the reversed position of the answer.

Input Format

n = 32-bit unsigned integer represented as an int

Output Format

the integer obtained by reversing all 32 bits

Constraints

  • 1 <= input size <= 10^5
  • -10^9 <= numeric values <= 10^9
  • n must satisfy the format described in inputFormat.

Examples

Example 1:

Input:

n = 43261596

Output:

964176192

Explanation:

This is the classic 00000010100101000001111010011100 example.

Example 2:

Input:

n = 0

Output:

0

Explanation:

All bits are zero, so the reverse is also zero.

Loading...
Reverse Bits - Bit Manipulation DSA Problem