Public
Edited
Oct 26, 2022
2 stars
Insert cell
Insert cell
Insert cell
littleEndianNum = {
const bits = littleEndianUInt8Array.length * 8
return new DataView(littleEndianArrayBuff)[`getUint${bits}`]()
}
Insert cell
littleEndianArrayBuff = toUIntBytes(bigEndianNum, true)
Insert cell
littleEndianUInt8Array = new Uint8Array(littleEndianArrayBuff)
Insert cell
bigEndianUInt8Array = new Uint8Array(toUIntBytes(bigEndianNum))
Insert cell
bigEndianConversionTest = {
const bits = bigEndianUInt8Array.length * 8
return new DataView(bigEndianArrayBuff)[`getUint${bits}`]()
}
Insert cell
bigEndianArrayBuff = toUIntBytes(bigEndianNum)
Insert cell
Insert cell
function toUIntBytes(x, littleEndian = false) {
if(x < 0) {
throw new Error('x must be >= 0')
}
const bits = minPower(x);
const bytes = bits / 8;
const arr = new ArrayBuffer(bytes);
const view = new DataView(arr);
view[`setUint${bits}`](0, x, littleEndian); // byteOffset = 0; litteEndian = false
return arr;
// return view
}
Insert cell
pot = [8,16,32,64] //powers of two
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more