Reverse bits of a 32-bit integer

Updated Apr 28, 2026

Short answer

Iterate through bits, shifting the result and adding the LSB of the input.

Deep explanation

This explores bitwise arithmetic and identity properties. Iterate through bits, shifting the result and adding the LSB of the input. These patterns are common in technical coding interviews.

Real-world example

Efficient memory allocation alignment checks.

Common mistakes

  • Not handling the case where n = 0 for power-of-two checks.

Follow-up questions

  • What is the time complexity?

More Bit Manipulation interview questions

View all →