What is Node.js Buffer.writeUIntBE() method?
Buffer.writeUIntBE() is a method used to write defined bytes to a buffer object using the big-endian format. It supports up to 6 bytes of accuracy.
Syntax
Buffer.writeUIntBE(value, offset, byteLength)
Parameters
-
value: Defines the number that is to be written to the buffer object. It should be unsigned. -
offset: Sets the number of bytes to skip before writing into the buffer. -
byteLength: Defines the number of bytes that are to be written into the buffer.
Return value
Returns the number of bytes written, plus the offset.
Code
At first, the buffer is declared and the size is set to 5. Later, Buffer.writeUIntBE() is called and the values are passed. Finally, the buffer is printed.
//Allocates buffer sizeconst buffer = Buffer.allocUnsafe(5);buffer.writeUIntBE(0x1314151617, 0, 5);// show the resultconsole.log(buffer);