Reverse Bits

Reverse bits of a given 32 bits signed integer.

Follow up: If this function is called many times, how would you optimize it?

Example 1
Inputn = 43261596
Output964176192
The 32-bit binary representation of 43261596 is reversed to produce 964176192.
Example 2
Inputn = 2147483644
Output1073741822
The 32-bit binary representation of 2147483644 is reversed to produce 1073741822.

Constraints

  • 0 <= n <= 2^31 - 2
  • n is even.

Asked at 10 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate