【发布时间】:2021-08-04 16:14:33
【问题描述】:
我在正在读取的文件中有一些二进制数据(十六进制):
00 00 00 18 66 74 79 70
我读取文件并将其转换为 arrayBuffer 以及 Uint8Array 和 Uint16Array。
const arrayBuffer = await selectedFile.arrayBuffer()
const uint8Array = new Uint8Array(arrayBuffer)
const uint16Array = new UInt16Array(arrayBuffer)
Uint8Array的内容如预期:
Decimal Hex
0: 0 0
1: 0 0
2: 0 0
3: 24 18
4: 102 66
5: 116 74
6: 121 79
7: 112 70
但在 uint16Array 中,两个字节被翻转。
Decimal Hex What I expected as Hex
0: 0 0 0
1: 6144 18 00 00 18
2: 29798 74 66 66 74
3: 28793 70 79 79 70
为什么两个字节会翻转?我该怎么做才能获得正确的订单,例如我需要搜索 0x6674。
【问题讨论】: