Last active
December 14, 2015 22:38
-
-
Save jarrodbell/5159311 to your computer and use it in GitHub Desktop.
JavaScript hex conversion snippets
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
// Convert 0-255 to hex byte: | |
String.fromCharCode(id) | |
// Convert 01-FF to hex byte: | |
String.fromCharCode(parseInt(id, 16)) | |
// Convert hex byte to 0-ff: | |
id.charCodeAt(0).toString(16); | |
// Convert hex byte to 00-FF: | |
("0"+id.charCodeAt(0).toString(16)).slice(-2).toUpperCase(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment