//十六进制转ASCII码
hexCharCodeToStr(hexCharCodeStr) {
var trimedStr = hexCharCodeStr.trim();
var rawStr = trimedStr.substr(0, 2).toLowerCase() === "0x" ? trimedStr.substr(2) : trimedStr;
var len = rawStr.length;
if (len % 2 !== 0) {
this.showToast('erro1')
return "";
}
var curCharCode;
var resultStr = [];
for (var i = 0; i < len; i = i + 2) {
curCharCode = parseInt(rawStr.substr(i, 2), 16);
resultStr.push(String.fromCharCode(curCharCode));
}
return resultStr.join("");
},
// 十进制转16进制字符串
strToArr(str) {
let arr = str.split('.')
const hexadecimalArr = arr.map(item => {
let s = parseInt(item).toString(16).toUpperCase()
return s.length < 2 ? `0${s}` : s
})
return hexadecimalArr.join('')
},
// 字符串转16进制
asclltoNum(str) {
for (let i = 0; i < str.length; i++) {
let charCode = str.charCodeAt(i);
this.hex += charCode.toString(16).toUpperCase()
}
console.log("hex", this.hex);
return this.calcStrBytes(this.hex)
},
// 获取字节数
calcStrBytes(str) {
if (typeof str !== 'string') {
throw new TypeError('需要字符串');
}
// console.log(str.split('').reduce((res, x) => res + (x.codePointAt(0).toString(16).length / 2), 0))
return str.split('').reduce((res, x) => res + (x.codePointAt(0).toString(16).length / 2), 0)
},