Reverse Bits

Easy · Bit Manipulation · Bit Manipulation · Divide and Conquer

Problem

Reverse the bits of a 32-bit unsigned integer and return the result.

The width is fixed at 32, so leading zeros participate in the reversal.

Examples

Input: n = 43261596
Output: 964176192

00000010100101000001111010011100 reversed is 00111001011110000010100101000000.

Input: n = 1
Output: 2147483648

The lowest bit moves to the highest position.

Constraints

Approaches

Follow-up

If this function is called many times, how would you optimise it?

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…