(ES6) ES6 (2016)

TypedArr (TA09)

   1:  const buffer = new ArrayBuffer(4);
   2:  const view = new DataView(buffer);
   3:  view.setUint32(0, 12345, false); // false for big-endian
   4:  
   5:  // Get the byte array
   6:  const byteArray = new Uint8Array(buffer);
   7:  console.log(byteArray); // Output: Uint8Array [ 0, 0, 48, 57 ] (big-endian)
   8:  
   9:  // Convert to little-endian by reversing the byte array
  10:  const littleEndianArray = Array.from(byteArray).reverse();
  11:  console.log(littleEndianArray); // Output: [57, 48, 0, 0] (little-endian)



 convert a big-endian byte array to a little-endian byte array (and vice versa) by using the Array.reverse()



 Uint8Array(4) [ 0, 0, 48, 57 ]
 [ 57, 48, 0, 0 ]





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/TA09.htm
<TAGS>  <ARTICLES>  <FRONT>  <CORE>  <MVC>  <ASP>  <NET>  <DATA>  <TASK>  <XML>  <KIOSK>  <NOTES>  <SQL>  <LINUX>  <MONO>  <FREEWARE>  <DOCS> <TRAVELS> <FLOWERS> <RESUME> < THANKS ME>