@Test public void testToByteArrayInt() { int[] sarr4 = {0xCAFEBABE, 0xDEADBEEF}; int[] sarr3 = {0xCAFEBA, 0xDEADBE}; int[] sarr2 = {0xCAFE, 0xDEAD}; int[] sarr1 = {0xCA, 0xFE, 0xBA, 0xBE}; Assert.assertArrayEquals(Bytes.toByteArray(sarr4, sarr4.length, 4, true), Bytes.toByteArray(0xCA, 0xFE, 0xBA, 0xBE, 0xDE, 0xAD, 0xBE, 0xEF)); Assert.assertArrayEquals(Bytes.toByteArray(sarr4, sarr4.length, 4, false), Bytes.toByteArray(0xBE, 0xBA, 0xFE, 0xCA, 0xEF, 0xBE, 0xAD, 0xDE)); Assert.assertArrayEquals(Bytes.toByteArray(sarr3, sarr3.length, 3, true), Bytes.toByteArray(0xCA, 0xFE, 0xBA, 0xDE, 0xAD, 0xBE)); Assert.assertArrayEquals(Bytes.toByteArray(sarr3, sarr3.length, 3, false), Bytes.toByteArray(0xBA, 0xFE, 0xCA, 0xBE, 0xAD, 0xDE)); Assert.assertArrayEquals(Bytes.toByteArray(sarr2, sarr2.length, 2, true), Bytes.toByteArray(0xCA, 0xFE, 0xDE, 0xAD)); Assert.assertArrayEquals(Bytes.toByteArray(sarr2, sarr2.length, 2, false), Bytes.toByteArray(0xFE, 0xCA, 0xAD, 0xDE)); Assert.assertArrayEquals(Bytes.toByteArray(sarr1, sarr1.length, 1, true), Bytes.toByteArray(0xCA, 0xFE, 0xBA, 0xBE)); Assert.assertArrayEquals(Bytes.toByteArray(sarr1, sarr1.length, 1, false), Bytes.toByteArray(0xCA, 0xFE, 0xBA, 0xBE)); }
public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; }
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; } }
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; }  }
Bytes { public static byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; }  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 byte[] toByteArray(int... uints) { byte[] bytez = new byte[uints.length]; for (int i = 0; i < uints.length; i++) { if (uints[i] > 255 || uints[i] < 0) { throw new IllegalArgumentException( "Cannot convert to byte. Number should be between 0 and (255) 0xff. " + "Number:" + uints[i]); } bytez[i] = (byte) (uints[i] & 0xff); } return bytez; }  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; }