Endianness defines the order of the sequence of multibyte data types (int, float, etc.) stored in the computer memory.
In little-endian, the last byte of the binary representation of the multibyte data type is stored first.
In big-endian, the first byte of the binary representation of the multibyte data type is stored first.
Buffer.writeFloatLE() method writes a 32 bits little-endian floating-point value to a buffer at a specified offset.
Buffer.writeFloatLE() method is defined as follows:
The method takes up to two parameters:
value: This is the 4-byte floating-point number to be written to the buffer. If the value is not a valid 32 bits little-endian floating-point number, the behavior is undefined.
offset: This is the number of bytes to skip before starting the write. The default value of
offset is 0.
offsetis an optional parameter.
offsetmust satisfy the condition: 0 <= offset <=
returns the number of bytes in the buffer
Buffer.writeFloatLE() method returns the sum of the
offset and the number of written bytes.
The code below shows the use of the
Buffer.writeFloatLE() method. We allocate an 8-byte buffer and write the value
offset 0. We then display the buffer.
//Allocate 8 bytes buffer const buf = Buffer.allocUnsafe(8); //Write 123.456 to buffer at offset 0 console.log(buf.writeFloatLE(0xffffffff,0)); //Display buffer console.log(buf);
View all Courses