Problems / Reverse Bits
Easy

Reverse Bits

Easy 0 submissions 10 coins +50 XP
Bit Manipulation Divide and Conquer
Problem Description
## Problem Reverse the bits of a given 32-bit unsigned integer `n` and return the result. ## Examples **Example 1:** ``` Input: n = 43261596 Binary: 00000010100101000001111010011100 Output: 964176192 Reversed binary: 00111001011110000010100101000000 ``` **Example 2:** ``` Input: n = 0 Output: 0 ``` **Example 3:** ``` Input: n = 1 Binary: 00000000000000000000000000000001 Output: 2147483648 Reversed binary: 10000000000000000000000000000000 ``` ## Hints - Iterate 32 times. In each step, shift the result left by 1, extract the LSB of `n` with `n & 1`, add it to the result, then shift `n` right by 1. - Alternatively, use a divide-and-conquer approach by swapping pairs of bits at increasing distances.
Constraints
- The input is treated as an unsigned 32-bit integer. - `0 <= n <= 2^32 - 1`

Need help?

Connect with expert programmers for real-time collaborative coding, video meetings, and whiteboard sessions via CodeConnect.

Video Call Whiteboard Live Coding Screen Share