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.
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
Parameter
Description
byteOffset
Where 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.
littleEndian
Optional. 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 Value
Description
BigInt
A 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.
Eight bytes of hash. The bytes are read big-endian, so they appear in the same order in the result.
Hex is the usual format. BigInt has toString(16) too, so the hash prints as cbf29ce484222325.
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.