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/hexadecimal and ASCII codes)

PHP中文网
PHP中文网Original
2017-04-01 15:36:111357browse

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+&#39;:\t&#39;+String.fromCharCode(i)+&#39;\t&#39;+&#39;\n&#39;;}else{ 
c+=i+&#39;:\t&#39;+String.fromCharCode(i)+&#39;\t&#39;;} 
} 
document.getElementById("abc").innerText=c; 
} 
<div id=&#39;abc&#39;></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)!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn