Buffer.writeBigInt64BE()方法是Buffer模塊中Buffer類的內置應用程序編程接口,用於將Big Endian 64位Big整數值以指定的偏移量寫入分配的緩衝區。
用法:
Buffer.writeBigInt64BE( value, offset )
參數:該方法接受上述和以下所述的兩個參數:
- value:此參數指定要寫入緩衝區的大整數值。它應該是有效的64位big endian Big整數值。當值不是此值時,行為是不確定的。
- offset:它指定在寫入之前要跳過的字節數,或者隻是表示緩衝區中的索引。 offset的值是0 <= offset <= Buffer.length-8。其默認值為0。
返回值:此方法返回一個整數值,該值是偏移量和寫入的字節數之和。
以下示例說明了Node.js中Buffer.writeDoubleBE()方法的使用:
範例1:
文件名:index.js
// Node.js program to demonstrate the
// buffer.writeBigInt64BE() method
const buf = Buffer.allocUnsafe(8);
// Writing big integer value into buffer
// by using writeBigInt64BE() method
buf.writeBigInt64BE(0x01030405060708n, 0);
// Display the buffer
console.log(buf);
使用以下命令運行index.js文件:
node index.js
輸出:
<Buffer 00 01 03 04 05 06 07 08>
範例2:
文件名:index.js
// Node.js program to demonstrate the
// buffer.writeBigInt64BE() method
const buf = Buffer.allocUnsafe(8);
// Writing big integer value into buffer
// by using writeBigInt64BE() method
buf.writeBigInt64BE(0xaa03040506efffn, 0);
// Display the buffer
console.log(buf);
使用以下命令運行index.js文件:
node index.js
輸出:
<Buffer 00 aa 03 04 05 06 ef ff>
參考: https://nodejs.org/dist/latest-v12.x/docs/api/buffer.html#buffer_buf_writebigint64be_value_offset
相關用法
- Node.js console.timeLog()用法及代碼示例
- Node.js GM bordercolor()用法及代碼示例
- Node.js GM flip()用法及代碼示例
- Node.js GM border()用法及代碼示例
- Node.js GM equalize()用法及代碼示例
- Node.js GM monochrome()用法及代碼示例
- Node.js GM enhance()用法及代碼示例
- Node.js GM flop()用法及代碼示例
- Node.js GM randomThreshold()用法及代碼示例
- Node.js GM operator()用法及代碼示例
- Node.js GM recolor()用法及代碼示例
- Node.js GM channel()用法及代碼示例
注:本文由純淨天空篩選整理自RohitPrasad3大神的英文原創作品 Node.js Buffer.writeBigInt64BE() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。