View Single Post
Old 03-04-2004, 07:49 AM   PM User | #11
liorean
The thread killer


 
Join Date: Feb 2003
Location: Umeå, Sweden
Posts: 5,575
Thanks: 0
Thanked 84 Times in 75 Posts
liorean will become famous soon enoughliorean will become famous soon enough
Q: How do I convert a decimal number to hexadecimal, and the other way around?

A: For converting a hexadecimal number to a decimal number, you use the parseInt function with a radix of 16, like this:
Code:
var nDecimal=parseInt(sHexadecimal, 16);
where sHexadecimal is a string containing a hexadecimal number.

For converting a decimal number to hexadecimal, you use the toString method with an argument of the radix you want to convert to, in this case 16, like this:
Code:
var sHexadecimal=nDecimal.toString(16);
where nDecimal is either a variable name, a number literal wrapped in parentheses, or a function giving a number as return value.
liorean is offline