Skip to content

Instantly share code, notes, and snippets.

@amorri40
Created August 22, 2012 23:04
Show Gist options
  • Save amorri40/3430429 to your computer and use it in GitHub Desktop.
Save amorri40/3430429 to your computer and use it in GitHub Desktop.
Javascript Byte to hex
var hexChar = ["0", "1", "2", "3", "4", "5", "6", "7","8", "9", "A", "B", "C", "D", "E", "F"];
function byteToHex(b) {
return hexChar[(b >> 4) & 0x0f] + hexChar[b & 0x0f];
}
@knandersen
Copy link

knandersen commented Jul 24, 2019

It looks like ES6 has a handy way of achieving the same thing:

(yournumber).toString(16)

example:

(255).toString(16); "ff"

https://2ality.com/2015/04/numbers-math-es6.html#new-integer-literals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment