Reverse Bits

IF
AlgoAxiomStaff Engineers
JSTS
Easy20 mins

Reverse bits of a given 32-bit unsigned integer.

Note: In some languages, such as Java, there is no unsigned integer type. In this case, both input and output will be given as a signed integer type. They should not affect your implementation, as the integer's internal binary representation is the same, whether it is signed or unsigned.

Examples

Example 1:

Input: n = 43261596 (binary: 00000010100101000001111010011100)

Output: 964176192 (binary: 00111001011110000010100101000000)

Example 2:

Input: n = 4294967293 (binary: 11111111111111111111111111111101)

Output: 3221225471 (binary: 10111111111111111111111111111111)

Constraints

  • The input must be a binary string of length 32
Source: Bitwise Manipulation pattern — AlgoAxiom
JavaScript
Test Case 1
root = [1, 2, 3]
Test Case 2
root = [1, 2, 3, 4, 5]
Idle