gyr*_*yre 9

您可以使用正则表达式Array#mapparseInt(string, radix):

var hex = 'AA5504B10000B5'

var typedArray = new Uint8Array(hex.match(/[\da-f]{2}/gi).map(function (h) {
  return parseInt(h, 16)
}))

console.log(typedArray)
console.log([0xAA, 0x55, 0x04, 0xB1, 0x00, 0x00, 0xB5])

var buffer = typedArray.buffer
Run Code Online (Sandbox Code Playgroud)


Jon*_*han 7

紧凑型单衬版本:

new Uint8Array('AA5504B10000B5'.match(/../g).map(h=>parseInt(h,16))).buffer
Run Code Online (Sandbox Code Playgroud)