faqts : Computers : Programming : Languages : JavaScript : Language Core : Numbers

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

75 of 119 people (63%) answered Yes
Recently 6 of 10 people (60%) answered Yes

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));