-
-
Save vongvisalsambath/81fc82167a21f1b1c7e1b29895d8a4f8 to your computer and use it in GitHub Desktop.
How to convert between integers and bytes 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
| // 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