Entry
How to covert a decimal number to a hexadecimal format?
How to convert a decimal number to a binary format?
How to convert a decimal number to another numerical system?
Feb 21st, 2000 09:47
Martin Honnen,
JavaScript has a
toString(numberBase)
method for that so by calling
toString(16)
on a number you get a string with the hexadecimal representation of the
number, by calling
toString(2)
you get the binary representation, by calling
toString(8)
you get the octal representation. That works for bases from 2..16.
Examples
var n = 10;
alert(n.toString(16));
alert(n.toString(8));
alert(n.toString(2));