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


Node.js Buffer.readDoubleBE()用法及代碼示例


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 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_readdoublebe_offset



相關用法


注:本文由純淨天空篩選整理自MerlynShelley大神的英文原創作品 Node.js | Buffer.readDoubleBE() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。