當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。