← Back to challenges

Reversing a Binary String

PythonHardbit_operationslanguage_fundamentals

Instructions

Write a function that takes an integer n, reverses the binary representation of that integer, and returns the new integer from the reversed binary.

Examples

reversed_binary_integer(10) ➞ 5
# 10 = 1010 -> 0101 = 5

reversed_binary_integer(12) ➞ 3
# 12 = 1100 -> 0011 = 3

reversed_binary_integer(25) ➞ 19
# 25 = 11001 -> 10011 = 19

reversed_binary_integer(45) ➞ 45
# 45 = 101101 -> 101101 = 45

Notes

All values of n will be positive.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Capitalize the Last Letter