Node.js Buffer.readDoubleBE() Method
Last Updated :
13 Oct, 2021
The
Buffer.readDoubleBE() Method in Node.js is used to read a 64-bit double from the buffer at the given offset with the Big Endian format.
Syntax:
Buffer.readDoubleBE( 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 big endian format.
Below examples illustrate the use of buf.readDoubleBE() Method in Node.js:
Example 1:
javascript
// Node program to demonstrate the
// Buffer.readDoubleBE() method
// Creating a buffer of given size
const buf = Buffer.from([10, 20, 30, 40, 50, 60, 70, 80]);
// Display the result
console.log("Functions of Buffer.readDoubleBe(int)");
console.log(buf.readDoubleBE(0))
console.log(buf);
Output:
Functions of Buffer.readDoubleBe(int)
4.0888790063059496e-260
<Buffer 0a 14 1e 28 32 3c 46 50>
Example 2:
javascript
// Node program to demonstrate the
// Buffer.readDoubleBE() method
// Creating a buffer of given size
const buf = Buffer.from([100, 200, 300, 400, 500, 600, 700, 800]);
// Display the result
console.log("Functions of Buffer.readDoubleBe(int)");
console.log(buf.readDoubleBE(5))
console.log(buf);
Output:
Functions of Buffer.readDoubleBe(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 5
. . .
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_readdoublebe_offset