(ES6) ES6 (2016)

TypedArr (TB02)

   1:  const buffer = new ArrayBuffer(2); // 2 bytes for a 16-bit integer
   2:  const view = new DataView(buffer);
   3:  
   4:  // Write a 16-bit integer in big-endian format
   5:  view.setUint16(0, 0x1234, false); // false for big-endian
   6:  
   7:  // Read the 16-bit integer in big-endian format
   8:  const bigEndianValue = view.getUint16(0, false);
   9:  console.log(bigEndianValue.toString(16)); // Output: "1234"
  10:  
  11:  // Read the 16-bit integer in little-endian format
  12:  const littleEndianValue = view.getUint16(0, true);
  13:  console.log(littleEndianValue.toString(16)); // Output: "3412"



Writing and Reading a 16-bit Integer

1234
3412





TypedArr context:






ES6 context:




Binary context:



Comments ( )
Link to this page: http://www.vb-net.com/JavascriptES6/TB02.htm
< THANKS ME>