HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavascriptCritical

How to convert decimal to hexadecimal in JavaScript

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
howconvertdecimalhexadecimaljavascript

Problem

How do you convert decimal values to their hexadecimal equivalent in JavaScript?

Solution

Convert a number to a hexadecimal string with:

hexString = yourNumber.toString(16);


And reverse the process with:

yourNumber = parseInt(hexString, 16);

Code Snippets

hexString = yourNumber.toString(16);
yourNumber = parseInt(hexString, 16);

Context

Stack Overflow Q#57803, score: 3274

Revisions (0)

No revisions yet.