buf.readInt16BE()

buf.readInt16BE(offset[, noAssert])
buf.readInt16LE(offset[, noAssert])

  • offset {Number} 0 <= offset <= buf.length - 2
  • noAssert {Boolean} 默认:false
  • 返回:{Number}
从该 Buffer 指定的带有特定尾数格式(readInt16BE() 返回一个较大的尾数,readInt16LE() 返回一个较小的尾数)的 offset 位置开始读取一个16位整数值。 设置 noAssert 为 true ,将跳过对 offset 的验证。这将允许 offset 超出缓冲区的末尾。 从 Buffer 里读取的整数数值会被解释执行为有符号的2的补码值。 ``` const buf = Buffer.from([1, -2, 3, 4]);

buf.readInt16BE();
// returns 510
buf.readInt16LE(1);
// returns 1022

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