Skip to content

Instantly share code, notes, and snippets.

@bravo-kernel
Created February 15, 2022 15:27
Show Gist options
  • Save bravo-kernel/3e7e5fe51aa2b68a2a24013be047ffa0 to your computer and use it in GitHub Desktop.
Save bravo-kernel/3e7e5fe51aa2b68a2a24013be047ffa0 to your computer and use it in GitHub Desktop.
Convert bytes array to hex in Javascript
/**
* Converts a bytes array into a hex string.
*
* @see {@link https://stackoverflow.com/a/34310051/9850103}
* @param bytes - Array with bytes
*/
export const bytesToHex = (bytes: Array<number>) => {
return Array.from(bytes, function (byte) {
return ("0" + (byte & 0xff).toString(16)).slice(-2)
}).join("")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment