Reverse an Unsigned 32-bit Value
Problem statement
Reverse exactly 32 binary digits of the nonnegative integer value, including leading zero bits. Return the reversed bit pattern as a nonnegative integer. The wire type is 64-bit so values above the signed 32-bit maximum remain positive.
Function
reverseBits32(value: long) → longExamples
Example 1
value = 1return = 2147483648One has 31 leading zeros followed by a 1; reversal moves that 1 to bit 31.
Example 2
value = 43261596return = 964176192The fixed-width reversal of 00000010100101000001111010011100 is 00111001011110000010100101000000.
Constraints
0 <= value <= 4294967295.