Javascript Convert string representation of hex value to hexadecimal

In Javascript, how do I convert a string representation of a hex value to its hex representation?

What I am returning from the checksum routine is the string value "FE". I need this hexadecimal representation of "\ xFE"

I cannot just do this, as this gives me an error:

var crc = "FE";
var hex = "\x" + crc;

This just gives me a new 4-character ASCII string:

var crc = "FE";
var hex = "0x" + "FE";

Thanks for any guidance.

+1
source share
2 answers

like this

var hex = parseInt("FF", 16);
+1
source

For the string, \xFEdo a backslash:var hex = '\\x'+'FE'

'FE' +('0xFE')

+('0xFE') , (224).toString(16) '0x'+((254).toString(16))

0

Source: https://habr.com/ru/post/1662865/


All Articles