using c#

javascript中非常方便的进制转换

09-02-27 13:34   View:602

javascript下的进制转换非常方便,系统已经提供内置方法,提供2~36进制间的转型。直接提供表示的有8进制、10进制、16进制。


var w=function(s){document.write('<br>'+s)};

//十进制转其他
var x=110;
w(x);
w(x.toString(8));
w(x.toString(32));
w(x.toString(16));

//其他转十进制
var x='110';
w(parseInt(x,2));
w(parseInt(x,8));
w(parseInt(x,16));

//其他转其他
//先用parseInt转成十进制再用toString转到目标进制

例如十六进制转换十进制

parseInt(”0xff”,16).toString(10)

------------------------------------

转载:http://blog.csdn.net/cuixiping/archive/2007/08/27/1760490.aspx

 

Feedback


  • No comments posted yet.
Title:
 
Name:
 
URL:

Comments:
 

Because of the cache,you may see your comments several minutes later.


Main Feeds

Contact Me Privacy

All Rights Reservered CnKker.Com 2006~2009 Powder By 龍天昌盛 QQ:256051