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:
const buf = Buffer.from([10, 20, 30, 40, 50, 60, 70, 80]);
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:
const buf = Buffer.from([100, 200, 300, 400, 500, 600, 700, 800]);
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
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
13 Oct, 2021
Like Article
Save Article