Skip to content

Instantly share code, notes, and snippets.

@uupaa
Last active August 29, 2015 14:12
Show Gist options
  • Select an option

  • Save uupaa/5d9172eefc8be5fbe8b1 to your computer and use it in GitHub Desktop.

Select an option

Save uupaa/5d9172eefc8be5fbe8b1 to your computer and use it in GitHub Desktop.
TypedArray endian
function testEndian() {
  var ab  = new ArrayBuffer(8);
  var u8  = new Uint8Array(ab);
  var u16 = new Uint16Array(ab);
  var f64 = new Float64Array(ab);

  f64[0] = 1.25;
  var result1 = Array.prototype.slice.call(u8);

  u16[0] = 0x1234;
  var result2 = u8[0] * 256 + u8[1];

  if (result1.join() === [0, 0, 0, 0, 0, 0, 244, 63].join() &&
      result2 === 0x3412) {
    // Mac Chrome, Mobile Safari, Chrome for Android, iOS Simulator
  } else {
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment