Node.js Buffer.readDoubleBE() 方法
Node.js 中的Buffer.readDoubleBE() 方法用于以 Big Endian 格式从给定偏移处的缓冲区读取 64 位双精度。
句法:
Buffer.readDoubleBE( offset )
参数:此方法接受单个参数偏移量,该偏移量保存开始读取之前要跳过的字节数。 offset 的值介于0 <= offset <= buf.length – 8之间。它的默认值为 0。
返回值:它以大端格式返回一个整数值。
下面的例子说明了在 Node.js 中使用 buf.readDoubleBE() 方法:
示例 1:
// Node program to demonstrate the
// Buffer.readDoubleBE() method
// Creating a buffer of given size
const buf = Buffer.from([10, 20, 30, 40, 50, 60, 70, 80]);
// Display the result
console.log("Functions of Buffer.readDoubleBe(int)");
console.log(buf.readDoubleBE(0))
console.log(buf);
输出:
Functions of Buffer.readDoubleBe(int)
4.0888790063059496e-260
示例 2:
// Node program to demonstrate the
// Buffer.readDoubleBE() method
// Creating a buffer of given size
const buf = Buffer.from([100, 200, 300, 400, 500, 600, 700, 800]);
// Display the result
console.log("Functions of Buffer.readDoubleBe(int)");
console.log(buf.readDoubleBE(5))
console.log(buf);
输出:
Functions of Buffer.readDoubleBe(int)
internal/buffer.js:72
throw new ERR_OUT_OF_RANGE(type || 'offset',
^
RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range.
It must be >= 0 and <= 0. Received 5
. . .
注意:以上程序将使用node index.js
命令编译运行。
参考: https://nodejs.org/docs/latest-v11.x/api/buffer.html#buffer_buf_readdoublebe_offset