using Java NIO's ByteBuffer is very simple:
Code1:
byte[] bytes = ByteBuffer.allocate(4).putInt(130776).array();
for (byte b : bytes) {
System.out.format("0x%x ", b);
}
output:
0x00 0x01 0xfe 0xd8
Code2:
public static final byte[] intToByteArray(int value) {
return new byte[] {
(byte)(value >>> 24),
(byte)(value >>> 16),
(byte)(value >>> 8),
(byte)value};
}
Code3:
byte[] IntToByteArray( int data ) {
byte[] result = new byte[4];
result[0] = (byte) ((data & 0xFF000000) >> 24);
result[1] = (byte) ((data & 0x00FF0000) >> 16);
result[2] = (byte) ((data & 0x0000FF00) >> 8);
result[3] = (byte) ((data & 0x000000FF) >> 0);
return result;
}