Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

node.js

How to use Node.js Buffer Module readUInt8()

Muhammad Ashir

buffer.readUInt() reads an 8-bit unsigned integer from the specified place in the buffer.

Prototype

buf.readUInt8([offset])

Parameters

  • offset: The number of bytes after which the data is to be read from the buffer object.

Return value

buf.readUInt() returns an 8-bit integer at the specified offset.

Code

const buf = Buffer.from([1, 99]);

console.log(buf.readUInt8(0));

console.log(buf.readUInt8(1));

const buf2 = Buffer.from("abc");

console.log(buf2.readUInt8(0));

The first buffer object, buf, is made of an array with two elements, and we use buf.readUInt() to read the unsigned integer values from the first and second index.

The second buffer object, buf2, is a string, and we use the buf2.readUInt() method to read the ASCII value of the characters at the specified offset.

RELATED TAGS

node.js

CONTRIBUTOR

Muhammad Ashir
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring