Skip to content

Instantly share code, notes, and snippets.

@aarondufall
Last active December 27, 2015 06:39
Show Gist options
  • Select an option

  • Save aarondufall/7283586 to your computer and use it in GitHub Desktop.

Select an option

Save aarondufall/7283586 to your computer and use it in GitHub Desktop.
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)
@danktec

danktec commented Nov 3, 2013

Copy link
Copy Markdown

Nice. that's a lot cleaner than my code!

@danktec

danktec commented Nov 3, 2013

Copy link
Copy Markdown

it seems kinda buggy tho, did you test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment