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

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]

JavaScript Convert Decimal/Hexadecimal

JavaScript String, Char, Encoding, Hexadecimal

JavaScript Number

BUY
Ξ£JS
JavaScript in Depth

JavaScript in Depth

Basic Syntax

Value Types

Variable

String

Property

Object and Inheritance

Array

Function

Constructor/Class

Iterable 🌟

Misc