
- 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 Where 條件
- 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.readDoubleBE() 方法
Node.JS Buffer.readDoubleBE() 方法用於從當前緩衝區物件中給定偏移量處讀取一個大端序雙精度 64 位數。
雙精度 64 位數也稱為 FP64 或 float64。使用時,它在計算機中佔用 64 位記憶體。
雙精度 64 位數分為符號位、指數位和尾數位。符號位佔 1 位,指數位佔 11 位,其餘 53 位(其中 52 位用於顯式儲存)由尾數位佔用。
符號位指示數字的正負號。
指數位是一個 11 位無符號整數,最小值為 0,最大值為 2047。
尾數位是 53 位。例如,一個數字是 120.53。因此,這裡的整數 12053 是尾數,$10^{-2}$ 是冪項,其中 -2 是指數。
語法
以下是 Node.JS Buffer.readDoubleBE() 方法的語法:
buf.readDoubleBE([offset])
引數
offset - 指示開始讀取位置的偏移量。偏移量大於或等於 0,也小於或等於 buffer.length-8。預設值為 0。
返回值
此方法返回當前緩衝區中給定偏移量處的 64 位大端序雙精度數。
示例
要建立緩衝區,我們將使用 NodeJS 的 Buffer.from() 方法:
const buffer = Buffer.from([11, 12, 13, 14, 15, 16, 17, 18]); console.log(buffer.readDoubleBE(0));
輸出
我們在此方法中使用的偏移量為 0。將返回第 0 位上的 64 位雙精度大端序數。上面建立的緩衝區長度為 8。因此,我們只能使用值為 0 的偏移量。如果任何值 >0,它將給出錯誤 ERR_OUT_OF_RANGE。
1.8681939987954357e-255 <Buffer 0b 0c 0d 0e 0f 10 11 12>
示例
讓我們建立一個 16 位的緩衝區,並檢視使用 Node.JS Buffer.readDoubleBE() 方法返回的值。
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 2:", buffer.readDoubleBE(2));
輸出
在上面的示例中,建立的緩衝區的長度為 16。因此,對於偏移量,我們可以使用 0 到 8 的值。
Length of buffer is 16 Reading at big integer at offset 2: 1.390671161566996e-309
示例
此示例將檢查如果偏移量大於 buffer.length -8 時發生的錯誤。讓我們建立一個長度為 8 的緩衝區,並且可以使用 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.readDoubleBE(1));
輸出
由於我們在上面的程式中使用了大於 0 的偏移量,因此它將丟擲如下所示的錯誤:
buffer length is 8 internal/buffer.js:58 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:58:9) at Buffer.readDoubleBackwards [as readDoubleBE] (internal/buffer.js:442:5) at Object.<anonymous> (C:\nodejsProject\src\testbuffer.js:3:59) at Module._compile (internal/modules/cjs/loader.js:816:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10) at Module.load (internal/modules/cjs/loader.js:685:32) at Function.Module._load (internal/modules/cjs/loader.js:620:12) at Function.Module.runMain (internal/modules/cjs/loader.js:877:12) at internal/main/run_main_module.js:21:11