I just converted an array of 8-bit numbers into an ArrayBuffer. Now I would like to convert it back to an array of 8-bit (1 byte) integers to double check they match. Wondering how to do that.
I just converted an array of 8-bit numbers into an ArrayBuffer. Now I would like to convert it back to an array of 8-bit (1 byte) integers to double check they match. Wondering how to do that.
Dataview allows you to inspect the contents of an ArrayBuffer. Something like this would likely work:
let arr = [];
let view = new DataView(arrayBuffer);
for (let i = 0; i<view.byteLength;i++){
arr.push(view.getInt8(i))
}
Try
let d = [10,20,40,50]
let u8b = new Uint8Array(d).buffer; // array buffer
let u8 = new Uint8Array(u8b);
let a = Array.from(u8);
console.log('d',d);
console.log('u8b',u8b);
console.log('u8',u8);
console.log('a',a);