What is the Buffer.readUInt8() method in Node.js?

The readUInt8() method reads an unsigned 8-bit integer from the buffer object at the specified offset and returns an integer.

An unsigned 8-bit integer is an unsigned whole or natural number ranging from 0 to +255.


buffer.readUInt8( offset )


  • offset: Number of bytes to skip before starting to read. Offset must be in the range 0 <= offset <= buf.length - 1. The default value of the offset is 0.


Example 1

In the following example:

  • In line 1, we construct the buffer object from [1,255].
  • In line 4, we print an unsigned 8-bit integer of 1.
  • In line 7, we print an unsigned 8-bit integer of 255.

Read more here: Source link