Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

javascript help


4:43 am on Apr 3, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Mar 15, 2010
votes: 0

How do you convert numbers between different bases in javascript? Can anybody help me on this.
6:37 am on Apr 3, 2010 (gmt 0)

Preferred Member

5+ Year Member

joined:Aug 18, 2008
votes: 0

Number.toString(rdx) accepts a radix parameter (the radix parameter must be an integer between 2 and 36):
var n = 11111111;
alert(n.toString(2)); //binary
alert(n.toString(10)); //decimal
alert(n.toString(16)); //hexadecimal

parseInt(s,rdx) also takes a radix parameter as it's second argument for going from string to number:
var nS = 'a98ac7';
alert(parseInt(nS, 16));