0

How do I convert an ASCII hex string into a character?

Examples:

6E - n
26 - &
45 - E

I have searched on the internet but only found answers for the decimal system, not the double-hex format.

Leo
  • 319
  • 3
  • 18

1 Answers1

1

Use a combination of parseInt() and String.fromCharCode():

const hex2Char = hex => String.fromCharCode(parseInt(hex, 16));

console.log(hex2Char('6E'));
console.log(hex2Char('26'));
console.log(hex2Char('45'));
Michael M.
  • 10,486
  • 9
  • 18
  • 34