Welcome to WebmasterWorld Guest from 54.221.165.245

Forum Moderators: open

Message Too Old, No Replies

javascript help

conversion

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

Junior Member

5+ Year Member

joined:Mar 15, 2010
posts:57
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
posts:408
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));
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members