Skip to content

Instantly share code, notes, and snippets.

@viktorkelemen
Last active December 19, 2015 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viktorkelemen/5941157 to your computer and use it in GitHub Desktop.
Save viktorkelemen/5941157 to your computer and use it in GitHub Desktop.
Reversed Binary Numbers
/*
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