class Bytes {

    public static short[] toShortArray(byte[] ba, int amount, boolean bigEndian) {
        final int size = determineSize(amount, ba.length, 2);
        short[] result = new short[size / 2];
        int i = 0;
        for (int j = 0; j < size; j += 2) {
            if (bigEndian) {
                result[i++] = (short) (ba[j] << 8 & 0xff00 | ba[j + 1] & 0xff);
            } else {
                result[i++] = (short) (ba[j + 1] << 8 & 0xff00 | ba[j] & 0xff);
            }
        }
        return result;
    }

}