Bird
Raised Fist0

Given the following code snippet for reversing bits of a 32-bit unsigned integer, what is the output when input n = 1?

easy🧾 Code Trace Q3 of Q15
Bit Manipulation - Reverse Bits
Given the following code snippet for reversing bits of a 32-bit unsigned integer, what is the output when input n = 1?
A0
B1
C4294967295
D2147483648
Step-by-Step Solution
Solution:
  1. Step 1: Understand input and output

    Input n=1 has only the least significant bit set.
  2. Step 2: Trace bit reversal

    Reversing bits moves the LSB to the MSB position, which is 2^31 = 2147483648.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Reversing 0b000...001 -> 0b100...000 [OK]
Quick Trick: Reversing LSB bit moves it to MSB position [OK]
Common Mistakes:
MISTAKES
  • Assuming output equals input
  • Confusing bit positions
Trap Explanation:
PITFALL
  • Candidates often forget that reversing bits moves LSB to MSB, resulting in large integer value.
Interviewer Note:
CONTEXT
  • Tests candidate's ability to mentally execute bitwise operations.
Master "Reverse Bits" in Bit Manipulation

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bit Manipulation Quizzes