
- Node.js 教程
- Node.js - 首頁
- Node.js - 簡介
- Node.js - 環境搭建
- Node.js - 第一個應用程式
- Node.js - REPL 終端
- Node.js - 命令列選項
- Node.js - 包管理器 (NPM)
- Node.js - 回撥函式概念
- Node.js - 上傳檔案
- Node.js - 傳送電子郵件
- Node.js - 事件
- Node.js - 事件迴圈
- Node.js - 事件發射器
- Node.js - 偵錯程式
- Node.js - 全域性物件
- Node.js - 控制檯
- Node.js - 程序
- Node.js - 應用程式擴充套件
- Node.js - 打包
- Node.js - Express 框架
- Node.js - RESTful API
- Node.js - 緩衝區
- Node.js - 流
- Node.js - 檔案系統
- Node.js MySQL
- Node.js - MySQL 入門
- Node.js - MySQL 建立資料庫
- Node.js - MySQL 建立表
- Node.js - MySQL 插入資料
- Node.js - MySQL 查詢資料
- Node.js - MySQL 條件查詢
- Node.js - MySQL 排序
- Node.js - MySQL 刪除資料
- Node.js - MySQL 更新資料
- Node.js - MySQL 連線查詢
- Node.js MongoDB
- Node.js - MongoDB 入門
- Node.js - MongoDB 建立資料庫
- Node.js - MongoDB 建立集合
- Node.js - MongoDB 插入資料
- Node.js - MongoDB 查詢資料
- Node.js - MongoDB 查詢
- Node.js - MongoDB 排序
- Node.js - MongoDB 刪除資料
- Node.js - MongoDB 更新資料
- Node.js - MongoDB 資料限制
- Node.js - MongoDB 連線查詢
- Node.js 模組
- Node.js - 模組
- Node.js - 內建模組
- Node.js - 實用程式模組
- Node.js - Web 模組
- Node.js 有用資源
- Node.js - 快速指南
- Node.js - 有用資源
- Node.js - 討論
Node.js - Buffer.readBigInt64BE() 方法
NodeJS Buffer.readBigInt64BE() 方法用於從緩衝區物件中給定偏移量讀取一個帶符號的大端序 64 位整數。
帶符號的 64 位整數範圍為 264-1。結果將是一個 20 位數字。
64 位整數的最小值是:-9,223,372,036,854,775,808。
64 位整數的最大值是:9,223,372,036,854,775,807。
在大端序系統中,最高有效位元組儲存在最低儲存地址。而小端序系統中,最低有效位元組儲存在最高儲存地址。
請注意,此方法從 Node 版本 12.0.0 開始可用。
語法
以下是 NodeJS readBigInt64BE() 方法的語法:
buf.readBigInt64LE(offset)
引數
buf.readBigInt64LE() 方法接受一個引數。解釋如下。
offset - 指示開始讀取位置的偏移量。偏移量大於等於 0 且小於等於 buffer.length-8。預設值為 0。
返回值
buf.readBigInt64LE() 方法返回給定偏移量處的 64 位帶符號整數。
示例
在下面的示例中,我們與 buffer.readBigInt64BE() 方法一起使用的偏移量為 0。將返回第 0 位的 64 位帶符號整數。上面建立的緩衝區長度為 8。因此我們只能使用值為 0 的偏移量。任何大於 0 的值都會引發錯誤 ERR_OUT_OF_RANGE。
const buffer = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]); console.log("buffer stored in memory as", buffer); console.log("Reading at big integer at offset 0:", buffer.readBigInt64BE(0));
輸出
buffer stored in memory as <Buffer 00 00 00 00 ff ff ff ff> Reading at big integer at offset 0: 4294967295n
示例
讓我們建立一個 16 位緩衝區,並檢視使用 readBigInt64BE() 方法返回的值。
const buffer = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,0xff, 0xff, 0xff, 0xff,0xff, 0xff, 0xff, 0xff]); console.log("Length of buffer is ", buffer.length); console.log("Reading at big integer at offset 0:", buffer.readBigInt64BE(2));
上面建立的緩衝區長度為 16。因此,對於偏移量,我們可以使用 0 到 8 的值。
輸出
Length of buffer is 16 Reading at big integer at offset 0: 281474976710655n
示例
在這個示例中,我們將檢查如果偏移量大於 buffer.length -8 時出現的錯誤。讓我們建立一個長度為 8 的緩衝區,並且可以使用 0 作為偏移量值。使用大於 0 的偏移量將引發如下所示的錯誤。
const buffer = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]); console.log("buffer length is ", buffer.length); console.log("Reading at big integer at offset 1:", buffer.readBigInt64BE(1));
輸出
buffer length is 8 internal/buffer.js:83 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 <= 0. Received 1 at boundsError (internal/buffer.js:83:9) at Buffer.readBigInt64BE (internal/buffer.js:152:5) at Object.<anonymous> (C:\nodejsProject\src\testbuffer.js:5:59) at Module._compile (internal/modules/cjs/loader.js:1063:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) at Module.load (internal/modules/cjs/loader.js:928:32) at Function.Module._load (internal/modules/cjs/loader.js:769:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12) at internal/main/run_main_module.js:17:47 { code: 'ERR_OUT_OF_RANGE's