Reverse Bits
Easy
Divide and Conquer
Bit Manipulation
Reverse bits of a given 32 bits unsigned integer. Given the decimal value of a 32-bit unsigned integer `n`, return *the decimal value of its bits reversed*.
Example 1
Input: n = 43261596
Output: 964176192
Explanation: 43261596 is 00000010100101000001111010011100 in binary, which reversed is 00111001011110000010100101000000 = 964176192.
Example 2
Input: n = 4294967293
Output: 3221225471

Constraints

  • The input must be a binary string of length 32, represented here as its unsigned decimal value (0 <= n <= 2³² - 1).
Time Complexity
O(1)
Space Complexity
O(1)
14
Case 1
Input: 43261596
Expected: 964176192
Case 2
Input: 4294967293
Expected: 3221225471
Case 3
Input: 1
Expected: 2147483648