binary.ts 656 B

12345678910111213141516171819
  1. /**
  2. * Copyright (c) 2017-2018 mol* contributors, licensed under MIT, See LICENSE file for more info.
  3. *
  4. * @author Alexander Rose <alexander.rose@weirdbyte.de>
  5. * @author David Sehnal <david.sehnal@gmail.com>
  6. */
  7. export const IsNativeEndianLittle = new Uint16Array(new Uint8Array([0x12, 0x34]).buffer)[0] === 0x3412;
  8. export function flipByteOrder(data: Uint8Array, bytes: number) {
  9. let buffer = new ArrayBuffer(data.length);
  10. let ret = new Uint8Array(buffer);
  11. for (let i = 0, n = data.length; i < n; i += bytes) {
  12. for (let j = 0; j < bytes; j++) {
  13. ret[i + bytes - j - 1] = data[i + j];
  14. }
  15. }
  16. return buffer;
  17. }