Geeksforgeeks

X

DAYS

:

HOUR

:

MINS

:

SEC

Error

Copied to Clipboard

Given a non-negative integer **n**. Reverse the bits of **n** and print the number obtained after reversing the bits.

**Input : **
N = 11
**Output:**
13
**Explanation:**
(11)_{10} = (1011)_{2}.
After reversing the bits we get:
(1101)_{2} = (13)_{10}.

**Example 2:**

**Input : **
N = 10
**Output:**
5
**Explanation:**
(10)_{10} = (1010)_{2}.
After reversing the bits we get:
(0101)_{2} = (101)_{2}
= (5)_{10}.

You don't need to read input or print anything. Your task is to complete the function reverseBits() which takes an integer N as input and returns the number obtained after reversing bits.

1 ≤ N ≤ 10^{9}

We are replacing the old Disqus forum with the new Discussions section given below.

Click here to view old Disqus comments.

Click here to view old Disqus comments.

Login to report an issue on this page.

We strongly recommend solving this problem on your own before viewing its editorial. Do you still want to view the editorial?

YesLoading...

Reverse Bits

...