Data Structures & Algorithms Bit Manipulation
💡
Exercise 156

Reverse Bits 20 XP Easy

LeetCode Ctrl+Enter Run Ctrl+S Save

Reverse the bits of a 32-bit unsigned integer.

# Input: 00000010100101000001111010011100 # Output: 00111001011110000010100101000000 # = 964176192

Process each of 32 bits: extract rightmost bit of n, shift into result from the left.

💡 Pro tip: Understand this problem deeply — don't just memorize the code. Try explaining the approach out loud as if teaching a friend. If you can explain it simply, you truly understand it!

📋 Instructions
Reverse bits of n=43261596. Print the result.
Loop 32 times: result = (result << 1) | (n & 1), n >>= 1. You've got this — take it step by step!
🧪 Test Cases
Input
reverseBits(43261596)
Expected
964176192
Test case 1
main.py
Hi! I'm Rex 👋
Output
Ready. Press ▶ Run or Ctrl+Enter.