Home > Article > Web Front-end > Character issues in JS (conversion between binary/decimal/hexadecimal and ASCII codes)
Character issues in JS (conversion between binary/decimal/hex and ASCII codes)
var a='11160 ';
alert(parseInt(a,2)); //将111做为2进制来转换,忽略60(不符合二进制),从左至右只将符合二进制数的进行转换 alert(parseInt(a,16)); //将所有的都进行转换
According to this method, it can actually be converted into any base
var a='1110'; alert(parseInt(a,10).toString(16)); //将A转换为10进制,然后再转换成16进制 同样也可以是其它进制
The following is the ASCII code:
function test(){ var a='ab'; var c=a.charCodeAt(1);//返回98 也就是b的AscII码 位置从0开始 var char=String.fromCharCode(98);返回小写的b } //小例子 function test(){ //输出AscII码扩展集中的字符 var c=""; for(var i=1;i<65536;i++){ if((i%10)==0){ c+=i+':\t'+String.fromCharCode(i)+'\t'+'\n';}else{ c+=i+':\t'+String.fromCharCode(i)+'\t';} } document.getElementById("abc").innerText=c; } <div id='abc'></div>
The above is the content of character issues in JS (conversion between binary/decimal/hexadecimal and ASCII codes). For more related content, please pay attention to the PHP Chinese website (www.php.cn)!