@Test public void testToIntArray() { int[] intArrBig = {0x7eac8a93, 0x66AABBCC}; int[] intArrLittle = {0x938aac7e, 0xCCBBAA66,}; byte[] barr = {0x7e, (byte) 0xac, (byte) 0x8a, (byte) 0x93, 0x66, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC}; Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, true), intArrBig); Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, false), intArrLittle); Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 4, true), intArrBig); Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 4, false), intArrLittle); barr = new byte[]{0x7e, (byte) 0xac, (byte) 0x8a, (byte) 0x93, 0x66, (byte) 0xAA}; intArrBig = new int[]{0x7eac8a, 0x9366aa}; intArrLittle = new int[]{0x8aac7e, 0xaa6693}; Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 3, true), intArrBig); Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 3, false), intArrLittle); barr = new byte[]{0x7e, (byte) 0xac, (byte) 0x8a, (byte) 0x93, 0x66, (byte) 0xAA}; intArrBig = new int[]{0x7eac, 0x8a93, 0x66aa}; intArrLittle = new int[]{0xac7e, 0x938a, 0xaa66}; Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 2, true), intArrBig); Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 2, false), intArrLittle); barr = new byte[]{0x7e, (byte) 0xac, (byte) 0x8a}; intArrBig = new int[]{0x7e, 0xac, 0x8a}; intArrLittle = new int[]{0x7e, 0xac, 0x8a}; Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 1, true), intArrBig); Assert.assertArrayEquals(Bytes.toIntArray(barr, barr.length, 1, false), intArrLittle); }
public static int[] toIntArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 4); int[] result = new int[size / 4]; int i = 0; for (int j = 0; j < size; j += 4) { if (bigEndian) { result[i++] = toInt(ba[j], ba[j + 1], ba[j + 2], ba[j + 3], true); } else { result[i++] = toInt(ba[j + 3], ba[j + 2], ba[j + 1], ba[j], true); } } return result; }
Bytes { public static int[] toIntArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 4); int[] result = new int[size / 4]; int i = 0; for (int j = 0; j < size; j += 4) { if (bigEndian) { result[i++] = toInt(ba[j], ba[j + 1], ba[j + 2], ba[j + 3], true); } else { result[i++] = toInt(ba[j + 3], ba[j + 2], ba[j + 1], ba[j], true); } } return result; } }
Bytes { public static int[] toIntArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 4); int[] result = new int[size / 4]; int i = 0; for (int j = 0; j < size; j += 4) { if (bigEndian) { result[i++] = toInt(ba[j], ba[j + 1], ba[j + 2], ba[j + 3], true); } else { result[i++] = toInt(ba[j + 3], ba[j + 2], ba[j + 1], ba[j], true); } } return result; }  }
Bytes { public static int[] toIntArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 4); int[] result = new int[size / 4]; int i = 0; for (int j = 0; j < size; j += 4) { if (bigEndian) { result[i++] = toInt(ba[j], ba[j + 1], ba[j + 2], ba[j + 3], true); } else { result[i++] = toInt(ba[j + 3], ba[j + 2], ba[j + 1], ba[j], true); } } return result; }  static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
      boolean bigEndian); static int[] toReducedBitIntArray(
      byte[] ba,
      final int amount,
      int bytePerInteger,
      int bitAmount,
      boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); }
Bytes { public static int[] toIntArray(byte[] ba, int amount, boolean bigEndian) { final int size = determineSize(amount, ba.length, 4); int[] result = new int[size / 4]; int i = 0; for (int j = 0; j < size; j += 4) { if (bigEndian) { result[i++] = toInt(ba[j], ba[j + 1], ba[j + 2], ba[j + 3], true); } else { result[i++] = toInt(ba[j + 3], ba[j + 2], ba[j + 1], ba[j], true); } } return result; }  static byte[] toByteArray(int... uints); static int toInt(byte[] pb, boolean bigEndian); static int normalize(int i, int bitCount); static void normalize(int iarr[], int bitCount); static byte[] toByteArray(int i, int size, boolean isBigEndian); static int toInt(byte b0, byte b1, byte b2, byte b3, boolean bigEndian); static byte[] toByteArray(int i, boolean bigEndian); static byte[] toByteArray(short i, boolean bigEndian); static int[] toIntArray(byte[] ba, int amount, boolean bigEndian); static int[] toIntArray(byte[] ba, final int amount, final int bytePerInteger,
      boolean bigEndian); static int[] toReducedBitIntArray(
      byte[] ba,
      final int amount,
      int bytePerInteger,
      int bitAmount,
      boolean bigEndian); static short[] toShortArray(byte[] ba, int amount, boolean bigEndian); static byte[] toByteArray(short[] sa, int amount, boolean bigEndian); static byte[] toByteArray(int[] ia, int amount, int bytePerInteger, boolean bigEndian); static String toHexWithZeros(byte b); static String toHex(byte b); static String toHex(byte[] bytes); static String toHexWithZeros(byte[] bytes); static void hexDump(OutputStream os, byte[] bytes, int columns); static void hexDump(byte[] bytes, int columns); static final byte[] EMPTY_BYTE_ARRAY; }