Skip to content

Instantly share code, notes, and snippets.

@AndreasMadsen
Created October 6, 2012 11:32
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 AndreasMadsen/3844679 to your computer and use it in GitHub Desktop.
Save AndreasMadsen/3844679 to your computer and use it in GitHub Desktop.
to bit one liner
var toBits = function (num) { return num.toString(2).split('').map(Number).reverse(); };
toBits(1) // [1]
toBits(2) // [1, 0]
toBits(4) // [1, 0, 0]
toBits(7) // [1, 1, 1]
toBits(8) // [1, 0, 0, 0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment