JavaScript: Convert Decimal/Hexadecimal
Decimal to Hexadecimal
console.log((15).toString(16).toUpperCase() === "F"); console.log((157).toString(16).toUpperCase() === "9D");
[see Number.prototype.toString]
Hexadecimal to Decimal
console.log(parseInt("f", 16) === 15); console.log(parseInt("ff", 16) === 255); console.log(parseInt("fff", 16) === 4095); console.log(parseInt("F", 16) === 15); console.log(parseInt("FF", 16) === 255); console.log(parseInt("Fff", 16) === 4095); console.log(parseInt("975d7", 16) === 619991);
[see Number.parseInt]