for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
/*!
* endianness
* Swap endianness in byte arrays.
* Copyright (c) 2017 Rafael da Silva Rocha.
* https://github.com/rochars/endianness
*
*/
/**
* Swap the endianness of units of information in a byte array.
* The original array is modified in-place.
* @param {!Array<number>|!Array<string>|Uint8Array} bytes The bytes.
* @param {number} offset The number of bytes of each unit of information.
function endianness(bytes, offset) {
let len = bytes.length;
let i = 0;
while (i < len) {
swap(bytes, offset, i);
i += offset;
}
* Swap the endianness of a unit of information in a byte array.
* @param {number} offset The number of bytes of the unit of information.
* @param {number} index The start index of the unit of information.
function swap(bytes, offset, index) {
let x = 0;
let y = offset - 1;
let limit = parseInt(offset / 2, 10);
let swap;
swap
while(x < limit) {
swap = bytes[index + x];
bytes[index + x] = bytes[index + y];
bytes[index + y] = swap;
x++;
y--;
module.exports = endianness;