Node.js | Buffer.writeUIntBE() Method
Buffer.writeUIntBE() method is used to write the specified bytes using big endian format to a Buffer object. It supports up to 6 bytes of accuracy. It’s behavior is undefined when you use the value anything other than unsigned integer.
Buffer.writeUIntBE( value, offset, byteLength )
Parameters: This method accept three parameters as mentioned above and described below:
- value: It specifies the number which need to be written to the Buffer object.
- offset: It specifies the number of bytes to skip before starting to write into the buffer. The value of offset lies 0 <= offset <= buf.length – byteLength.
- byteLength: It specifies the number of bytes to write into the buffer. The value of byteLength lies 0 < byteLength <= 6.
Return value: It returns the offset plus the number of bytes written.
Below examples illustrate the use of Buffer.writeUIntBE() Method in Node.js:
<Buffer 13 14 15 16> <Buffer 13 13 14 14 15 15>
Before filling buffer <Buffer 00 00 00 00 00 00 00 00> After filling 6 bytes <Buffer aa 13 13 14 75 86 00 00> After filling next 2 bytes <Buffer aa 13 13 14 75 86 01 23>
Note: The above program will compile and run by using the
node index.js command.