JS: Convert Decimal, Hexadecimal
Decimal to Hexadecimal
console.log((15).toString(16).toUpperCase() === "F"); console.log((157).toString(16).toUpperCase() === "9D");
Hexadecimal to Decimal
// direct hexadecimal input // case doesn't matter console.log(0xff === 255); console.log(0xFF === 255); // convert hexadecimal to decimal console.log(parseInt("ff", 16) === 255); console.log(parseInt("FF", 16) === 255);
〔see Number.parseInt〕