Skip to content

Instantly share code, notes, and snippets.

@zuk
Created March 19, 2010 22:04
Show Gist options
  • Save zuk/338248 to your computer and use it in GitHub Desktop.
Save zuk/338248 to your computer and use it in GitHub Desktop.
How to convert between integers and bytes in JavaScript
// Here's how to do basic integer<->byte (string/char) operations in JavaScript.
// Took me a good while to dig this up.
function intToChar(integer) {
return String.fromCharCode(integer)
}
function charToInt(char) {
return char.charCodeAt(0)
}
// Example:
intToChar(90) // --> "Z"
charToInt("Z") // --> 90
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment