javascript将二进制转为字符串
用js将二进制转为字符串,代码如下:
var a = "00110000001100000011011";
var array = new Array();
for(var i=0;i<a.length;i=i+8){
var num = parseInt(a.substr(i,8),2);
array.push(num);
}
console.log(array.toString());
var str = "";
for(var x=0;x<array.length;x++){
var y = String.fromCharCode(array[x]);
str += y;
}
console.log(str);
var str2 = "";
for(var j=0;j<str.length;j=j+4){
console.log(str.substr(j,4));
str2 += String.fromCharCode(parseInt(str.substr(j,4),16));
}
console.log(str2);