Skip to content

Instantly share code, notes, and snippets.

@kessler
Last active July 2, 2016 13:18
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 kessler/d0273fd6c191f4ff7746d378e1883ae7 to your computer and use it in GitHub Desktop.
Save kessler/d0273fd6c191f4ff7746d378e1883ae7 to your computer and use it in GitHub Desktop.
function toBits(a, res) {
if (a === 0) return
let r = a % 2
if (r === 0) { res.push(0) } else { res.push(1) }
toBits(Math.floor(a / 2), res)
}
function dec2bin(dec){
return (dec >>> 0).toString(2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment