Compare Revisions

DataView

Revision 377193:

Revision 377193 by Nfroidure on

Revision 391009:

Revision 391009 by vjeux on

Title:
DataView
DataView
Slug:
JavaScript/Typed_arrays/DataView
JavaScript/Typed_arrays/DataView
Tags:
"NeedsContent","JavaScript typed arrays","JavaScript"
"NeedsContent","JavaScript typed arrays","JavaScript"
Content:

Revision 377193
Revision 391009
nn429    <h2 id="Detect_endianness">
430      Detect endianness
431    </h2>
432    <p>
433      You'll probably need to detect the type of architecture you
 >r script is running, here is a little trick to check it :
434    </p>
435    <pre class="brush: js">
436var littleEndian = (function() {
437  var buffer = new ArrayBuffer(2);
438  new DataView(buffer).setInt16(0, 256, true);
439  return new Int16Array(buffer)[0] === 256;
440})();
441console.log(littleEndian); // true ou false
442</pre>
t430      Detect endiannesst
431    </h2>
432    <p>
433      You'll probably need to detect the type of architecture you
>r script is running, here is a little trick to check it : 
434    </p>
435    <p>
436      &nbsp;
437    </p>
438    <pre class="brush: js">
439var littleEndian=(function()
440  {
441  var b=new ArrayBuffer(2);
442  (new DataView(b)).setInt16(0,256,true);
443  return (new Int16Array(b))[0] == 256;
444  })();
445console.log(littleEndian); // true ou false
446</pre>
447    <h2>

Back to History