Bytes { public static byte[] intToBytes(int v) { byte[] bytes = new byte[Integer.BYTES] ; setInt(v, bytes); return bytes ; } private  Bytes(); static int compare(byte[] x1, byte[] x2); static int compareByte(byte b1, byte b2); static byte[] copyOf(byte[] bytes); static byte[] copyOf(byte[] bytes, int start); static byte[] copyOf(byte[] bytes, int start, int length); static byte[] intToBytes(int v); static byte[] longToBytes(long v); static final int getInt(byte[]b); static final int getInt(byte[]b, int idx); static final long getLong(byte[]b); static final long getLong(byte[]b, int idx); static final void setInt(int value, byte[]b); static final void setInt(int x, byte[]b, int idx); static final void setLong(long value, byte[]b); static final void setLong(long value, byte[] b, int idx); static byte[] packInt(int val); static byte[] packLong(long val); static byte[] string2bytes(String x); static String bytes2string(byte[] x); static int toByteBuffer(CharSequence s, ByteBuffer bb); static int toByteBuffer(CharSequence s, ByteBuffer bb, CharsetEncoder enc); static String fromByteBuffer(ByteBuffer bb); static String fromByteBuffer(ByteBuffer bb, CharsetDecoder dec); static String asHex(byte[] bytes); static String asHexUC(byte[] bytes); static String asHexLC(byte[] bytes); static String asHex(byte[] bytes, int start, int finish, char[] hexDigits); static String asHex(byte b); static String asHexUC(byte b); static String asHexLC(byte b); static int hexCharToInt(char c); final static byte[] hexDigitsUC; final static byte[] hexDigitsLC; }
@Test public void intToBytes1() { byte[] b = Bytes.intToBytes(0xF1020304); assertEquals(Integer.BYTES, b.length); assertEquals(0xF1, b[0]&0xFF); assertEquals(0x02, b[1]); assertEquals(0x03, b[2]); assertEquals(0x04, b[3]); }