Node.js中的Buffer.readDoubleBE()方法用于以Big Endian格式从给定偏移量的缓冲区中读取64位double。
用法:
Buffer.readDoubleBE( offset )
参数:此方法接受单个参数偏移量,该偏移量包含开始读取之前要跳过的字节数。 offset的值介于0之间
返回值:它以big endian格式返回整数值。
以下示例说明了在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 <Buffer 0a 14 1e 28 32 3c 46 50>
范例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 andNote: The above program will compile and run by using the
node index.js
command.Reference: https://nodejs.org/docs/latest-v11.x/api/buffer.html#buffer_buf_readdoublebe_offset
相关用法
注:本文由纯净天空筛选整理自MerlynShelley大神的英文原创作品 Node.js | Buffer.readDoubleBE() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。