Created
March 19, 2010 22:04
-
-
Save zuk/338248 to your computer and use it in GitHub Desktop.
How to convert between integers and bytes in JavaScript
This file contains 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
// 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