javascript 字符转16进制

 

var str="我是中国人";
document.write("The Unicode for the first character is: " + str.charCodeAt(0).toString(16) + "<br />") //获取到的是10进制 必须toString(16)转换
document.write("The Unicode for the second character is: " + str.charCodeAt(1).toString(16) + "<br />")
document.write("The Unicode for the third character is: " + str.charCodeAt(2).toString(16))

 

 

进制转换

//十进制转其他  
var x=110;  
alert(x);  
alert(x.toString(8));  
alert(x.toString(32));  
alert(x.toString(16));  
//其他转十进制  
var x='110';  
alert(parseInt(x,2));  
alert(parseInt(x,8));  
alert(parseInt(x,16));  
//其他转其他  
//先用parseInt转成十进制再用toString转到目标进制  
alert(String.fromCharCode(parseInt(141,8)))  
alert(parseInt('ff',16).toString(2));

 

posted on 2017-01-03 19:15  小乔流水人家  阅读(224)  评论(0)    收藏  举报

导航