JavaScript: Convert Decimal/Hexadecimal

By Xah Lee. Date: . Last updated: .

Decimal to Hexadecimal

console.log((15).toString(16).toUpperCase() === "F");

console.log((157).toString(16).toUpperCase() === "9D");

[see Number.prototype.toString]

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]

JavaScript Convert Decimal, Hexadecimal, Binary

JavaScript String, Char, Encoding, Hexadecimal

JavaScript Number

BUY
ΣJS
JavaScript in Depth