2

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.

2 Answers 2

1

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);

Sign up to request clarification or add additional context in comments.

Comments

1

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))
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.