Convert hexadecimal string to an array of Uint8 values
Converting a string to an array of Uint8 values is often used in cryptography because it allows for the manipulation of individual bytes of data.
const fromHex = (s) => {
let result = new Uint8Array(s.length / 2);
for (let i = 0; i < s.length / 2; i++) {
result[i] = parseInt(s.substr(2 * i, 2), 16);
}
return result;
}new Uint8Array(Buffer.from(s, 'hex'));Last updated