@Test public void testToByteArrayShort() { byte[] baBe = {0x7e, (byte) 0xac, (byte) 0x8a, (byte) 0x93}; byte[] baLe = {(byte) 0xac, 0x7e, (byte) 0x93, (byte) 0x8a}; short[] sarr = {0x7eac, (short) 0x8a93}; Assert.assertArrayEquals(Bytes.toByteArray(sarr, sarr.length, true), baBe); Assert.assertArrayEquals(Bytes.toByteArray(sarr, sarr.length, false), baLe); }
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; }