0

How to convert uint64 values to ArrayBuffers? I've only found the reversal in the link below.

Does anyone have an optimum way of two way conversion? both ways. from uint64 to arraybuffers and arraybuffers to uint64

How to Read 64-bit Integer from an ArrayBuffer / DataView in JavaScript

JSNewbie
  • 31
  • 6

1 Answers1

0

It's easy.

  1. Create a BigUint64Array with the length you want.
  2. Populate it (optional).
  3. A reference to the underlying ArrayBuffer is in the .buffer property.

Every time you change an element of the BigUint64Array, the ArrayBuffer also changes.

const typedArr = new BigUint64Array(100);

for (let i = 0n; i < typedArr.length; i++)
  typedArr[i] = i;

const arrayBuffer = typedArr.buffer;
D. Pardal
  • 6,173
  • 1
  • 17
  • 37