Diwali Offer!Flat 20% OFF
Enroll Now
PrakalpanaLive online tech training

198. Reverse Bits

EasyDay 59 of 60Bit Manipulation & Math

Reverse the bits of a 32-bit unsigned integer n: bit 0 becomes bit 31, bit 1 becomes bit 30, and so on. In the tests n and the answer are plain non-negative numbers between 0 and 2^32 minus 1.

Example 1
Input: n = 43261596
Output: 964176192
00000010100101000001111010011100 reversed is 00111001011110000010100101000000.
Example 2
Input: n = 1
Output: 2147483648
The lowest bit moves to the highest position, giving 2^31.
Constraints
  • 0 <= n <= 2^32 - 1 (an unsigned 32-bit value)
Hints
Frequently asked at: Apple, Amazon, Qualcomm
Ctrl + Enter runs the examples

Not sure what to learn next?

A 1-on-1 session with an industry mentor and a roadmap built for you. How it works

  1. 1Discuss your goals
  2. 2Get a personal plan
  3. 3Start learning
Book for β‚Ή200/ 30 min