How to convert a hex string to a byte and a byte to a hex string in Javascript?
Here's a node.js specific approach, taking advantage of the the Buffer class provided by the node standard lib.
https://nodejs.org/api/buffer.html#buffer_buffers_and_character_encodings
To get the byte (0-255) value:
Buffer.from('80', 'hex')[0];
// outputs 128
And to convert back:
Buffer.from([128]).toString('hex');
// outputs '80'
To convert to utf8:
Buffer.from('80', 'hex').toString('utf8');
You can make use of Number.prototype.toString and parseInt.
The key is to make use of the radix
parameters to do the conversions for you.
var bytestring = Number('0x' + hexstring).toString(10); // '128'
parseInt(bytestring, 2).toString(16); // '80'