Reverse Bits

TopicDifficultyCompanies
Mathematical Algorithms
EASY
Amazon

Given a non-negative integer numwrite a program to return the number obtained after reversing the bits of num.

Problem Note

  • The actual binary representation of the number is being considered for reversing the bits, no leading 0’s are being considered.

Example 1

Input: 13 
Output: 11
Explanation: Binary representation of 13 is 1101. After reversing the bits we get 1011 which is equal to 11.

Example 2

Input: 6
Output: 3
Explanation: Binary representation of 6 is 110.After reversing the bits we get 011 which is equal to 3.

Code Editor

Practice and Learn

Best way to learn is through solving real problems. Practice this problem in this code editor.