Skip to content

Instantly share code, notes, and snippets.

@rtoal
Created June 21, 2014 21:08
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 rtoal/237004173eef07337f84 to your computer and use it in GitHub Desktop.
Save rtoal/237004173eef07337f84 to your computer and use it in GitHub Desktop.
8-bit bytestring hack in JavaScript
function byteString(n) {
if (n < 0 || n > 255 || n % 1 !== 0) {
throw new Error(n + " does not fit in a byte");
}
return ("000000000" + n.toString(2)).substr(-8)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment