Skip to content
BytePatterns

Reverse Bit Order

EasyBit Manipulation#bit-shifting#accumulator~20m

Problem

Treat a non-negative whole number as a fixed field of 32 binary digits, padded with zeros on the left. Return the value you get by reversing the order of those 32 digits, so the lowest digit becomes the highest and vice versa. The width is always 32, whatever the size of the input.

Examples

Input:  value = 1
Output: 2147483648
Why:    the single low digit moves all the way to the top of the field
Input:  value = 3
Output: 3221225472
Why:    the two low digits become the two highest ones
Input:  value = 0
Output: 0
Why:    edge case, a field of zeros reads the same in either direction

Hints

0 / 3

Stuck on the idea rather than the code? Binary and Bitwise Ops covers it.