1、字符传转化为二进制
erCode(str) {
let result = [];
let list = str.split("");
for (var i = 0; i < list.length; i++) {
if (i != 0) {
result.push(" ");
}
let item = list[i];
let binaryStr = item.charCodeAt().toString(2);
result.push(binaryStr);
}
return result.join("");
},
2、二进制转化为字符串
strCode(str) {
var result = [];
var list = str.split(" ");
for (var i = 0; i < list.length; i++) {
var item = list[i];
var asciiCode = parseInt(item, 2); //对字符串进行解析(二进制转化)
var charValue = String.fromCharCode(asciiCode);
result.push(charValue);
}
return result.join("");
},