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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more