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?

44 of 155 people (28%) answered Yes
Recently 5 of 10 people (50%) answered Yes

Entry

How to convert a hexadecimal number to a decimal one?
How to convert a binary number to a decimal one?
How to convert a number from a certain number system to a decimal one?

Feb 21st, 2000 09:58
Martin Honnen,


If you get string input of numbers in a representation other than 
decimal representation you can use
  parseInt('string', numberBase)
to convert that input to a decimal number for example
  var sixteenHex = '10';
  var sixteen = parseInt(sixteenHex, 16);
to convert from hex to decimal,
  var sixteenBinary = '10000';
  var sixteen = parseInt(sixteenBinary, 2);
to convert form binary to decimal,
  var sixteenOctal = '20';
  var sixteen = parseInt(sixteenOctal, 8);
to convert from octal to decimal.