TypedArr (TB04)
1: const buffer = new ArrayBuffer(8); // 8 bytes for multiple values
2: const view = new DataView(buffer);
3:
4: // Write a 16-bit integer and a 32-bit integer in little-endian format
5: view.setUint16(0, 0x1234, true); // 16-bit integer at offset 0
6: view.setUint32(2, 0x56789ABC, true); // 32-bit integer at offset 2
7:
8: // Read the values back
9: const uint16Value = view.getUint16(0, true);
10: const uint32Value = view.getUint32(2, true);
11:
12: console.log(uint16Value.toString(16)); // Output: "1234"
13: console.log(uint32Value.toString(16)); // Output: "56789abc"
Writing and Reading Multiple Values 1234 56789abc
TypedArr context:
ES6 context:
Binary context:
Comments (
)
)
Link to this page:
http://www.vb-net.com/JavascriptES6/TB04.htm
|
|