1.ArrayBuffer转16进度字符串
// ArrayBuffer转16进度字符串示例 // ab2hex(buffer) { // const hexArr = Array.prototype.map.call( // new Uint8Array(buffer), // function(bit) { // return ('00' + bit.toString(16)).slice(-2) // } // ) // return hexArr.join('') // }, ab2hex(arrayBuffer) { return Array.prototype.map.call(new Uint8Array(arrayBuffer), x => ('00' + x.toString(16)).slice(-2)).join(''); },
2.十六进制转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) { console.log("存在非法字符!"); 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(""); },
标签:十六进制,return,trimedStr,16,ArrayBuffer,var,uniapp From: https://www.cnblogs.com/zhangyouwu/p/17995570