Last active
December 27, 2015 06:39
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
function decToBin(num, acc){ | |
var acc = acc || "" | |
if (Math.floor(num) == 0) { | |
console.log(parseInt(acc)) | |
return parseInt(acc) | |
} | |
acc = Math.floor(num % 2) + acc | |
decToBin(num / 2, acc) | |
} | |
decToBin(253)// == 11111011) | |
decToBin(153)// == 10011001) | |
decToBin(22)// == 10100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
it seems kinda buggy tho, did you test?