1234567891011121314151617181920212223 |
- function buf2hex(buffer) { // buffer is an ArrayBuffer
- return [...new Uint8Array(buffer)]
- .map(x => x.toString(16).padStart(2, '0'))
- .join('');
- }
- function hex2ab(hex){
- let typedArray = new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function (h) {
- return parseInt(h, 16)
- }))
- let buffer = typedArray.buffer
- return buffer
- }
- function hexStrToBuffer(str){
- // 填充首位
- if(str.length % 2){str=`0${str}`}
-
- for(let i=0;i<str.length;i+=2){
- hex2ab
- }
- }
- export default {buf2hex,hex2ab}
|