Back to problems

Reverse Bits

Algorithm · Medium

You are given a non-negative integer n that fits in 32 bits. Treat it as an unsigned 32‑bit value and reverse the order of every bit in that 32‑bit pattern. The bit that originally sat at the least significant position is moved to the most significant position, the next bit becomes the second most significant, and so on through all 32 positions. The reversal includes all leading zeros: for example, 1 is represented with 31 zero bits above its only set bit, and all those…

Checking your access…