Home > Web Front-end > JS Tutorial > 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中文网
Release: 2017-04-01 15:36:11
Original
1417 people have browsed it

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)); //将所有的都进行转换
Copy after login

According to this method, it can actually be converted into any base

var a='1110'; 
alert(parseInt(a,10).toString(16)); //将A转换为10进制,然后再转换成16进制 同样也可以是其它进制
Copy after login

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>
Copy after login

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)!

Related labels:
source:php.cn
Statement of this Website
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
Latest Articles by Author
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template