【发布时间】:2022-01-03 12:25:47
【问题描述】:
如何将 int 转换为 Uint8Array 作为 javascript(nodejs) 中的小端序
在 python 中将 int 转换为字节时,我得到了这个输出
int(20).to_bytes(2, 'little') # out as Uint8Array([20,0]) <- 2 bytes
int(60).to_bytes(2, 'little') # out as Uint8Array([60,0]) <- 2 bytes
int(256).to_bytes(2, 'little') # out as Uint8Array([0,1]) <- 2 bytes(0,1 <-- 255 +1)
int(512).to_bytes(2, 'little') # out as Uint8Array([0,1]) <- 2 bytes(0,2 <-- 256*2)
int(1641167820).to_bytes(4, 'little') # out as Uint8Array([204,59,210,97])<- 4 bytes(0,2)
..一个字节中的最大数量是(255), 它在nodejs中有一些内置函数与python中的(.to_bytes)相同吗?
【问题讨论】:
标签: javascript python node.js byte uint8array