How to convert decimal to hexadecimal in JavaScript

Luke Smith picture Luke Smith · Sep 12, 2008 · Viewed 990k times · Source

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

Answer

Prestaul picture Prestaul · Sep 12, 2008

Convert a number to a hexadecimal string with:

hexString = yourNumber.toString(16);

And reverse the process with:

yourNumber = parseInt(hexString, 16);