Last active
December 19, 2015 10:29
-
-
Save viktorkelemen/5941157 to your computer and use it in GitHub Desktop.
Reversed Binary Numbers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Task | |
Your task will be to write a program for reversing numbers in binary. | |
For instance, the binary representation of 13 is 1101, | |
and reversing it gives 1011, which corresponds to number 11. | |
Input | |
The input contains a single line with an integer N, 1 ≤ N ≤ 1000000000. | |
Output | |
Output one line with one integer, | |
the number we get by reversing the binary representation of N. | |
*/ | |
function reverseBinary(num) { | |
return parseInt( | |
num | |
.toString(2) | |
.split('') | |
.reverse() | |
.join(''), | |
2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment