Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Node.js Buffer.readBigInt64BE() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The Buffer.readBigInt64BE() method is used to read 64-bit Big integer from a buffer object at a given offset and returns the result in Big endian.

Syntax: 

buffer.readBigInt64BE( offset )

Parameters: This method accepts a single parameter offset which specifies the position of buffer object. It represents the number of bytes to skip before starting to read. The value of offset lies within the range 0 to buffer.length – 8. The default value is 0.

Return value: This method reads an signed 64-bit Big integer at the specified offset in Big endian.

Example 1: Filename: index.js

javascript




// Node.js program to demonstrate the
// buffer.readBigInt64BE() method
const buff = Buffer.from([0x00, 0x00,
    0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
 
// Getting big integer value by
// using readBigInt64BE method
const value = buff.readBigInt64BE(0);
 
// Display the result
console.log("Big Integer :- " + value);


Run the index.js file using the following command: 
 

node index.js

Output: 
 

Big Integer :- 4294967295

Example 2: 
Filename: index.js 
 

javascript




// Node.js program to demonstrate the
// buffer.readBigInt64BE() method
const buff = Buffer.from([0x00, 0x00
   , 0x01, 0x00, 0xfe, 0xff, 0xff, 0xff]);
 
// Getting big integer value by
// using readBigInt64BE method
const value = buff.readBigInt64BE(1);
 
// Display the result
console.log("Big Integer :- " + value);


Run the index.js file using the following command: 
 

node index.js

Output: 
 

internal/buffer.js:77
  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 1
    at boundsError (internal/buffer.js:77:9)
    at Buffer.readBigInt64BE (internal/buffer.js:146:5)
    at Object. (F:\java\GFG.js:7:20)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'ERR_OUT_OF_RANGE'
}

The above example shows the error because its parameters are not in the valid range.
Reference: https://nodejs.org/dist/latest-v12.x/docs/api/buffer.html#buffer_buf_readbigint64be_offset
 


My Personal Notes arrow_drop_up
Last Updated : 07 Feb, 2023
Like Article
Save Article
Similar Reads
Related Tutorials