JavaScript DataView getBigUnit64() Method



The JavaScript DataView getBigUint64() method is used to retrieve 8-byte data segments starting from a specified byte offset of this DataView. Later on, it decodes them as 64-bit unsigned integers. You can retrieve multiple bytes from any offset within the bounds of the DataView.

This method throws a 'RangeError' exception if you try to read data from a position that exceeds the valid bounds of the DataView.

Syntax

Following is the syntax of the JavaScript DataView getBigUnit64() method −

getBigUnit64(byteOffset, littleEndian)

Parameters

This method accepts two parameters named 'byteOffset' and 'littleEndian', which are described below −

  • byteOffset − The position in the DataView from which to read the data.
  • littleEndian − It indicates whether the data is stored in little-endian or big-endian format.

Return value

This method returns a BigInt in the range from 0 to 264 - 1, inclusive.

Example 1

The following program demonstrates the usage of the JavaScript DataView getBigUint64() method.






Output

The above program returns the stored value.

The byte offset: 0
Value: 9223372036854775807
The stored value: 9223372036854775807

Example 2

The following is another example of the setBigUnit64() method. We use this method to retrieve an 8-byte data segment of the data view from a specified byte offset 1.






Output

After executing the program mentioned above, it will return an 8-byte data segment as −

The byte offset: 1
The data_view.getBigUnit64(1) method returns: 72623859790382856

Example 3

If the value of the byteOffset parameter falls outside the bounds of this data view, it will throw a 'RangeError' exception.






Output

Once the above program is executed, it will throw an exception as −

The byte offset: 1
Value: 9223372036854775807
TypeError: data_view.getBigUnit64 is not a function
Advertisements