
- 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.readUIntBE() 方法
NodeJS 的 Buffer.readUIntBE() 方法將根據位元組長度和偏移量讀取一定數量的位元組,並從使用的緩衝區中返回大端格式的無符號整數。
語法
以下是 **Node.JS Buffer.readUIntBE() 方法** 的語法:
buf.readUIntBE(offset, byteLength)
引數
此方法接受兩個引數。下面解釋一下。
**offset** - 指示開始讀取位置的偏移量。偏移量大於或等於 0,也小於或等於 buffer.length-bytelength。預設值為 0。
**byteLength** - 您要讀取的位元組數。byteLength 必須介於 0 到 6 之間。
返回值
此方法返回大端格式的無符號整數,該整數在緩衝區中具有給定偏移量值的 bytelength 位元組數。
示例
要建立緩衝區,我們將使用 NodeJS Buffer.from() 方法:
const buffer = Buffer.from([11, 12, 13, 14, 15, 16]); console.log(buffer); console.log(buffer.readUIntBE(0, 2));
輸出
我們與此方法一起使用的偏移量為 0。使用的位元組長度為 2。因此,從第 0 個偏移量開始,它將讀取位元組長度為 2 的位元組,並以大端格式返回結果。
<Buffer 0b 0c 0d 0e 0f 10> 2828
示例
在此示例中,讓我們列印以十六進位制形式獲得的輸出,如下所示:
const buffer = Buffer.from([11, 12, 13, 14, 15, 16]); console.log(buffer); console.log(buffer.readUIntBE(0, 2).toString(16));
輸出
<Buffer 0b 0c 0d 0e 0f 10> b0c
示例
眾所周知,我們可以使用從 0 到 buffer.length-bytelength 的偏移量。因此,如果緩衝區長度為 6,並且使用的位元組長度為 6,則我們可以將偏移量用作 0。使用大於 0 的值將導致錯誤:ERR_OUT_OF_RANGE。
const buffer = Buffer.from([11, 12, 13, 14, 15, 16]); console.log(buffer); console.log("The buffer length is :"+ buffer.length); console.log(buffer.readUIntBE(1, 6).toString(16));
輸出
<Buffer 0b 0c 0d 0e 0f 10> The buffer length is :6 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 readUInt48BE (internal/buffer.js:177:5) at Buffer.readUIntBE (internal/buffer.js:157:12) at Object.<anonymous> (C:\nodejsProject\src\testbuffer.js:5:20) 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
nodejs_buffer_module.htm
廣告