JavaScript DataView getBigUint64() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Instance method

Definition

getBigUint64() reads eight bytes from a DataView and returns an unsigned 64-bit whole number as a BigInt, from 0n up to 18446744073709551615n. Unsigned means it never returns a negative value, which suits sizes, counters, hashes and 64-bit IDs. It reads big-endian by default; pass true for little-endian bytes.

Remember
const view = new DataView(new ArrayBuffer(8));
view.setUint8(7, 1);
view.getBigUint64(0);          // 1n
view.getBigUint64(0, true);    // 72057594037927936n
view.getBigUint64(4);          // RangeError

Syntax

Call getBigUint64() on a DataView object with a byte position and, if the data is little-endian, true.

JavaScript
dataview.getBigUint64(byteOffset)
dataview.getBigUint64(byteOffset, littleEndian)
CallWhat it does
view.getBigUint64(byteOffset)Reads the 8 bytes starting at byteOffset in big-endian order (most significant byte first) and returns an unsigned whole number (never negative) from 0n to 18446744073709551615n.
view.getBigUint64(byteOffset, true)Reads the same 8 bytes in little-endian order (least significant byte first), the order used by most file formats from PCs, such as WAV and BMP.

Added in ES2020 together with BigInt. Every current browser and runtime has it. Unlike a BigUint64Array, a DataView has no alignment rule: getBigUint64() works at any byte position, even one that is not a multiple of 8.

Library declarations
JavaScript
DataView.prototype.getBigUint64(byteOffset)
DataView.prototype.getBigUint64(byteOffset, littleEndian)

// returns a BigInt: 0n to 18446744073709551615n
// reads 8 bytes starting at byteOffset (counted from the start of the view)
// needs byteOffset + 8 <= view.byteLength, else RangeError
// littleEndian: false or left out = big-endian

Parameters

ParameterDescription
byteOffsetWhere to start reading, counted in bytes from the start of the view (not of the underlying buffer). It is converted to a whole number, so 1.9 means 1 and "2" means 2. All 8 bytes must fit: byteOffset + 8 may not be larger than view.byteLength. A negative or too-large offset throws a RangeError.
littleEndianOptional. Leave it out (or pass false) for big-endian: the most significant of the 8 bytes comes first. Pass true for little-endian: the least significant byte comes first. Any truthy value, such as 1, also means little-endian.

Return Value

Return ValueDescription
BigIntA BigInt from 0n to 18446744073709551615n, built from the 8 bytes at byteOffset. Print it with String(), and use Number() only when it is small enough.

JavaScript Examples

Example 1 — Read a 5 TiB File Size

Archive and disk formats store file sizes in 8 bytes, because 4 bytes stop just above 4 GB. Read a little-endian size field.

JavaScript
const view = new DataView(new ArrayBuffer(8));
view.setBigUint64(0, 5497558138880n, true);    // a 5 TiB backup file

const bytes = view.getBigUint64(0, true);
console.log(String(bytes));                          // 5497558138880
console.log(String(bytes / 1024n ** 4n) + " TiB");   // 5 TiB
Try It Yourself

How It Works

  1. Sizes can pass 4 GB. A 32-bit unsigned number stops at 4294967295 bytes, so large files need a 64-bit size field.
  2. Little-endian, as in ZIP files. The size was written with true, so getBigUint64(0, true) is needed to read 5497558138880n.
  3. BigInt arithmetic. 1024n ** 4n is one tebibyte; BigInt division gives exactly 5n.

Example 2 — Show a 64-bit Hash in Hex and Decimal

Hash functions often produce 64-bit results. These 8 bytes are the well-known starting value of the FNV-1a hash.

JavaScript
const bytes = new Uint8Array([0xcb, 0xf2, 0x9c, 0xe4, 0x84, 0x22, 0x23, 0x25]);
const view = new DataView(bytes.buffer);

const hash = view.getBigUint64(0);
console.log(hash.toString(16));   // cbf29ce484222325
console.log(String(hash));        // 14695981039346656037
console.log(hash > 0n);           // true
Try It Yourself

How It Works

  1. Eight bytes of hash. The bytes are read big-endian, so they appear in the same order in the result.
  2. Hex is the usual format. BigInt has toString(16) too, so the hash prints as cbf29ce484222325.
  3. Unsigned keeps it positive. The first byte, cb, has its top bit set; getBigUint64() still returns a positive number, where getBigInt64() would give a negative one.

Example 3 — One 64-bit Read vs Two 32-bit Halves

Older code often stores a 64-bit number as a high and a low 32-bit part. Compare one getBigUint64() call with joining the halves by hand.

JavaScript
const view = new DataView(new ArrayBuffer(8));
view.setUint32(0, 1);            // high half
view.setUint32(4, 500);          // low half

const whole = view.getBigUint64(0);
const joined = (BigInt(view.getUint32(0)) << 32n) | BigInt(view.getUint32(4));
console.log(String(whole));      // 4294967796
console.log(whole === joined);   // true
Try It Yourself

How It Works

  1. Two 32-bit halves. The high part (1) goes into bytes 0 to 3 and the low part (500) into bytes 4 to 7.
  2. One call reads both. getBigUint64(0) reads all 8 bytes big-endian: 1 × 4294967296 + 500 = 4294967796n.
  3. The manual way gives the same. Shifting the high half left by 32 bits and combining it with the low half using | produces the identical BigInt.

Browser & Runtime Support

getBigUint64() arrived in ES2020, together with BigInt and BigUint64Array.

✓ ES2020 · Widely available

DataView.prototype.getBigUint64()

Every current browser and runtime supports it. Only very old engines without BigInt lack it.

97% Current browser support
Google Chrome Modern versions · Desktop & Mobile
Full support
Mozilla Firefox Modern versions · Desktop & Mobile
Full support
Apple Safari Modern versions · macOS & iOS
Full support
Microsoft Edge Modern versions · Chromium
Full support
Opera Modern versions
Full support
Samsung Internet Modern versions · Android
Full support
Internet Explorer No BigInt support
Not supported
Node.js Current releases · checked on Node 24
Supported
Deno Current releases
Supported
Bun Current releases
Supported
getBigUint64() All current engines

Bottom line: Safe in today’s browsers. If you must support an engine without BigInt, check typeof BigInt === "function" first.

Frequently Asked Questions

A BigInt from 0n to 18446744073709551615n, read from eight bytes. It is never negative.
When the value can be larger than 4294967295, for example file sizes over 4 GB, nanosecond times or 64-bit hashes.
Call toString(16) on the BigInt. Add padStart(16, "0") if you want all 16 hex digits.
Yes, with Number(value), but only values up to 9007199254740991 stay exact. Larger values are rounded.
Yes, there is no alignment rule. Any offset works as long as offset + 8 is not larger than the view byteLength.

Next: getFloat16()

Move on to decimals: read a compact 2-byte floating point number.

getFloat16() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful