(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 ( )
<00>  <01>  <02>  <03>  <04>  <05>  <06>  <07>  <08>  <09>  <10>  <11>  <12>  <13>  <14>  <15>  <16>  <17>  <18>  <19>  <20>  <21>  <22>  <23>  <24>  <25
Link to this page: http://www.vb-net.com/JavascriptES6/TB02.htm
<TAGS>  <ARTICLES>  <FRONT>  <CORE>  <MVC>  <ASP>  <NET>  <DATA>  <TASK>  <XML>  <KIOSK>  <NOTES>  <SQL>  <LINUX>  <MONO>  <FREEWARE>  <DOCS> <TRAVELS> <FLOWERS> <RESUME> < THANKS ME>