Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

node.js
buffer
bigint
communitycreator

What is the Buffer.readBigInt64BE() method Node.js?

Syed Muhammad Ali Mustafa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Overview

The Buffer.readBigInt64BE() method in Node.js is used to read 64 bits from a specified offset from a buffer in Big Endianthe most significant value is stored at the lowest storage address format.

Syntax

The Buffer.readBigInt64BE() method can be declared as shown in the code snippet below:


Buffer.readBigInt64BE(offset)

Parameter

offset: The offset determines the number of bytes to skip before reading the buffer.

In other words, it is the index of the buffer.

  • The offset value should be greater than -1 and less than the buffer length i.e., - 7.
  • The default value of offset is 0.

Return value

The Buffer.readBigInt64BE() method returns a 64 bit integer.

Code

Consider the code snippet below, which demonstrates the use of the Buffer.readBigInt64BE() method:

const buff = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
console.log("buff stored in memory as", buff);
console.log("Reading at offset 0:", buff.readBigInt64BE(0));

Output

buff stored in memory as <Buffer 00 00 00 00 ff ff ff ff>
Reading at offset 0: 4294967295

Explanation

  • A buffer buff is declared in line 1.

  • The Buffer.readBigInt64BE() method is used in line 5 to get 64 bits from the index 0 in the big-endian format.

As one index of the buffer is 8 bits, we need to read 8 indices of the buffer.

The Buffer.readBigInt64BE() reads 8 indices of buff in big-endian format and returns a 64-bit number.

RELATED TAGS

node.js
buffer
bigint
communitycreator

CONTRIBUTOR

Syed Muhammad Ali Mustafa

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring