Skip to content

Instantly share code, notes, and snippets.

@jarrodbell
Last active December 14, 2015 22:38
Show Gist options
  • Save jarrodbell/5159311 to your computer and use it in GitHub Desktop.
Save jarrodbell/5159311 to your computer and use it in GitHub Desktop.
JavaScript hex conversion snippets
// 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