Convert a number to a hexadecimal string:
let number = 4579; let hexStr = number.toString(16); console.log(hexStr);
The reverse will be done like this:
let hexStr = '12ab'; let number = parseInt(hexStr, 16); console.log(number);
Decimal and Hexadecimal Number¶
The decimal number system has only ten digits from 0 to 9. Each value represents 0,1,2,3,4,5,6, 7,8 and 9 in this number system. The base is 10, as it has only ten digits.
The Hex number system has sixteen alphanumeric values from 0 to 9 and A to F. Each value represents 0,1,2,3,4,5,6, 7,8,9, A, B, C, D, E, and F in this number system. The base of the hex system is 16, as it has 16 alphanumeric values.