TypedArr (TB05)
1: const buffer = new ArrayBuffer(4); // 4 bytes for a 32-bit integer
2: const view = new DataView(buffer);
3:
4: // Write a 32-bit integer in big-endian format
5: view.setUint32(0, 0x12345678, false); // false for big-endian
6:
7: // Read the 32-bit integer in little-endian format
8: const littleEndianValue = view.getUint32(0, true);
9: console.log(littleEndianValue.toString(16)); // Output: "78563412" (switched endianness)
Switching Endianness 78563412
TypedArr context:
ES6 context:
Binary context:
Comments (
)
)
Link to this page:
http://www.vb-net.com/JavascriptES6/TB05.htm
|
|