Open In App

Node.js Buffer.writeUInt32LE() Method

The Buffer.writeUInt32LE() method is used to write specified bytes using Little endian format to the buffer object. The value contains a valid unassigned 32-bit integer.

Syntax:



Buffer.writeUInt32LE( value, offset )

Parameters: This method accept two parameters as mentioned above and described below:

Return value: It returns an integer value offset plus number of bytes written.



Example 1:




// Node.js program to demonstrate the  
// Buffer.writeUInt32LE() Method
  
// Allocate a buffer
const buf = Buffer.allocUnsafe(4);
  
// Write the buffer element in LE format
buf.writeUInt32LE(0xabcdabcd, 0);
  
// Display the buffer list
console.log(buf);
  
// Write the buffer element in LE format
buf.writeUInt32LE(0xfacedcba, 0);
  
// Display the buffer list
console.log(buf);

Output:

<Buffer cd ab cd ab>
<Buffer ba dc ce fa>

Example 2:




// Node.js program to demonstrate the  
// Buffer.writeUInt32LE() Method
  
// Allocate a buffer
const buf = Buffer.allocUnsafe(4);
  
// Write the buffer element in LE format
buf.writeUInt32LE(0xabce, 0);
  
// Display the buffer list
console.log(buf);
  
// Write the buffer element in LE format
buf.writeUInt32LE(0xeab, 0);
  
// Display the buffer list
console.log(buf);

Output:

<Buffer ce ab 00 00>
<Buffer ab 0e 00 00>

Note: The above program will compile and run by using the node index.js command.

Reference: https://nodejs.org/api/buffer.html#buffer_buf_writeuint32le_value_offset


Article Tags :