buf.readIntBE()

buf.readIntBE(offset, byteLength[, noAssert])
buf.readIntLE(offset, byteLength[, noAssert])

  • offset {Number} 0 <= offset <= buf.length - byteLength
  • byteLength {Number} 0 < byteLength <= 6
  • noAssert {Boolean} 默认:false
  • 返回:{Number}

从该 Buffer 指定的 offset 位置开始读取 byteLength 字节数,并将结果解释执行为一个有符号的2的补码值。支持多达48位精度的值。例如:

const buf = Buffer.allocUnsafe(6);
buf.writeUInt16LE(0x90ab, 0);
buf.writeUInt32LE(0x12345678, 2);
buf.readIntLE(0, 6).toString(16); // Specify 6 bytes (48 bits)
// Returns: '1234567890ab'

buf.readIntBE(0, 6).toString(16);
// Returns: -546f87a9cbee

设置 noAssert 为 true ,将跳过对 offset 的验证。这将允许 offset 超出缓冲区的末尾。

posted @ 2018-11-05 13:22  sfornt  阅读(437)  评论(0编辑  收藏  举报