Reverse bits
MediumGiven an 16-bit unsigned integer
n
, write a function that reverse's the bits of n
and returns the output number.Let's take the binary representation of
n = 72
as an example:0000 0000 0100 1000 = 72
Your function should return the decimal number
4608
, the reversed binary number:0001 0010 0000 0000 = 4608
Try it first
Solution
6 Essential Primitives Coding Interview Problems
Master Primitives by trying the coding challenges below.
- 1.Swap bitsEasy
- 2.Power of twoEasy
- 3.Count bitsMedium
- 4.Reverse bitsMedium
- 5.Find duplicateMedium
- 6.Bitwise additionHard