Skip to content

Instantly share code, notes, and snippets.

@shurane
Created May 5, 2019 00:37
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 shurane/54f56336700f417ae9ce333381f4e7fa to your computer and use it in GitHub Desktop.
Save shurane/54f56336700f417ae9ce333381f4e7fa to your computer and use it in GitHub Desktop.
function numToBinaryString(num, padding=8) {
const n = num.toString(2);
const paddedString = "0".repeat(padding);
return paddedString.substr(n.length) + n;
}
for (let i = 0; i < 20; i++){
console.log(i, numToBinaryString(i));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment