Created
June 21, 2014 21:08
-
-
Save rtoal/237004173eef07337f84 to your computer and use it in GitHub Desktop.
8-bit bytestring hack in JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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