当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Node.js Buffer.readDoubleLE()用法及代码示例


Node.js中的Buffer.readDoubleLE()方法用于以Little Endian格式从给定偏移量的缓冲区中读取64位double。

用法:

Buffer.readDoubleLE( offset )

参数:此方法接受单个参数偏移量,该偏移量包含开始读取之前要跳过的字节数。 offset的值介于0之间


返回值:它以小尾数格式返回整数值。

以下示例说明了在Node.js中使用buf.readDoubleLE()方法:

范例1:

// Node program to demonstrate the 
// Buffer.readDoubleLE() method 
  
// Creating a buffer of given size 
const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]); 
  
// Display the result 
console.log(buf.readDoubleLE(0)); 
console.log(buf);

输出:

5.447603722011605e-270
<Buffer 01 02 03 04 05 06 07 08>

范例2:

// Node program to demonstrate the 
// Buffer.readDoubleBE() method 
  
// Creating a buffer of given size 
const buf = Buffer.from([11, 22, 33, 44, 55, 66, 77, 88]); 
  
// Display the result 
console.log("Functions of Buffer.readDoubleLE(int)"); 
console.log(buf.readDoubleLE(55)); 
console.log(buf);

输出:

Functions of Buffer.readDoubleLE(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 

Note: 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_readdoublele_offset



相关用法


注:本文由纯净天空筛选整理自MerlynShelley大神的英文原创作品 Node.js | Buffer.readDoubleLE() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。