79721692

Date: 2025-07-31 18:22:17
Score: 0.5
Natty:
Report link

BigUint64Array / BigInt64Array or DataView.setBigUint64 / DataView.setBigInt64 could be used to get bytes of JS BigInt

const v = 433791696840n;

// uses system endianness; usually little endian
const a = new Uint8Array(new BigUint64Array([ v ]).buffer);
console.log(a);
const b = new Uint8Array(new BigInt64Array([ -v ]).buffer);
console.log(b);

// endian could be set manually
const c = new Uint8Array(8);
const dv = new DataView(c.buffer);
dv.setBigUint64(0, v, true); // little endian
// dv.setBigUint64(0, v, false); // big endian
// dv.setBigUint64(0, v); // big endian
console.log(c);

Reasons:
  • Probably link only (1):
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: kajkal