Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想问一下,如何使用 buffer.writeInt16BE() 在缓冲区中存储一个数字(JS 中的整数)。
假设我有一个数字,例如
var a = 40000;
40000(10) = 9C40 (16)
如何将 40000 存储在大小为 2 的缓冲区中,所以它看起来像:
<9c, 40>
您不能使用buf.writeInt16BE(),因为 40000 大于 32768。但是,如果您使用buf.writeUInt16BE(),您可以将 40000 写入缓冲区就好了。
buf.writeInt16BE()
buf.writeUInt16BE()