Math Fundamentals18 sections · 814 units
Open in Course

Problem - Reverse Bits

LeetCode 190

Given a 32-bit unsigned integer nn, reverse its bits. For example, if n=43261596n = 43261596 (binary 0000001010010100000111101001110000000010100101000001111010011100), return 964176192964176192 (binary 0011100101111000001010010100000000111001011110000010100101000000).

Reversing bits means the leftmost bit becomes the rightmost, the second-left becomes second-right, and so on. This is not the same as reversing the decimal representation.

Think about how you can build the reversed number bit by bit. You extract each bit from nn (right to left) and place it into the result (left to right). Before reading on, try to design an algorithm.