Reverse Bits

Advanced

Reverse Bits Challenge πŸš€

In this challenge, you'll explore the wild world of binary numbers! Imagine bit values like little switches that can be turned on (1) or off (0). We want you to reverse the order of these switches for a given integer.

When a number is converted to its binary form, it becomes a sequence of 0s and 1s. For example, the number 5 in binary is 101. Reversing it gives us 101, which is still 5. Now let's try 13, which is 1101 in binary and becomes 1011 when reversed, which is 11 in decimal.

Your task is to write a function reverse_bits that takes an integer and returns the new integer formed by reversing the binary digits of the input number.

Examples:

reverse_bits(5) # Output: 5 reverse_bits(13) # Output: 11 reverse_bits(0) # Output: 0 reverse_bits(32) # Output: 1

Hint: 😎 You might want to use Python's built-in functions to convert between binary and decimal forms.

Have fun switching those bits!

Geek
Inputs

Arg 1:

5
Expected Output
5
Actual Output