Node.js Buffer.readDoubleLE() Method
Last Updated :
13 Oct, 2021
Improve
The Buffer.readDoubleLE() method in Node.js is used to read a 64-bit double from the buffer at the given offset with Little Endian format.
Syntax:
javascript
Output:
javascript
Output:
Buffer.readDoubleLE( offset )Parameters: This method accepts single parameter offset which holds the number of bytes to skip before starting to read. The value of offset lies between 0 <= offset <= buf.length - 8. Its default value is 0. Return Value: It returns an integer value in little endian format. Below examples illustrate the use of buf.readDoubleLE() Method in Node.js: Example 1:
// Node program to demonstrate the
// Buffer.readDoubleLE() method
// Creating a buffer of given size
const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
// Display the result
console.log(buf.readDoubleLE(0));
console.log(buf);
5.447603722011605e-270 <Buffer 01 02 03 04 05 06 07 08>Example 2:
// Node program to demonstrate the
// Buffer.readDoubleBE() method
// Creating a buffer of given size
const buf = Buffer.from([11, 22, 33, 44, 55, 66, 77, 88]);
// Display the result
console.log("Functions of Buffer.readDoubleLE(int)");
console.log(buf.readDoubleLE(55));
console.log(buf);
Functions of Buffer.readDoubleLE(int) internal/buffer.js:72 throw new ERR_OUT_OF_RANGE(type || 'offset', ^ RangeError [ERR_OUT_OF_RANGE]: The value of "offset" is out of range. It must be >= 0 and <= 0. Received 55 . . .Note: The above program will compile and run by using the
node index.js
command.
Reference: https://nodejs.org/docs/latest-v11.x/api/buffer.html#buffer_buf_readdoublele_offset