Buffer.readFloatBE()方法是Buffer模块中Buffer类的内置应用程序编程接口,用于将Big Endian 32位浮点值读取到指定偏移量处的已分配缓冲区。
用法:
Buffer.readFloatBE( offset )
参数:此方法接受单个参数偏移量,该偏移量指定在读取之前要跳过的字节数。 offset的值为0。默认值为0。
返回值:它以big endian格式返回整数值。
以下示例说明了在Node.js中使用buf.readFloatBE()方法:
范例1:
// Node program to demonstrate the
// Buffer.readFloatBE(INTEGER) 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.readFloatBE(int)");
console.log(buf.readFloatBE(0))
console.log(buf);
输出:
Functions of Buffer.readFloatBE(int) 7.13161255447549e-33 <Buffer 0a 14 1e 28 32 3c 46 50>
范例2:
// Node program to demonstrate the
// Buffer.readFloatBE(INTEGER) 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.readFloatBE(int)");
console.log(buf.readFloatBE(5))
console.log(buf);
输出:
Functions of Buffer.readFloatBE(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_readfloatbe_offset
相关用法
注:本文由纯净天空筛选整理自MerlynShelley大神的英文原创作品 Node.js | Buffer.readFloatBE() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。