Java tutorial
//package com.java2s; import java.nio.ByteBuffer; public class Main { public static byte[] intToBytes(int x) { ByteBuffer buffer = ByteBuffer.allocate(4); buffer.putInt(0, x); byte[] array = buffer.array(); reverseArray(array); return array; } private static void reverseArray(byte[] a) { int i = 0, n = a.length - 1; while (n > 2 * i) { byte x = a[i]; a[i] = a[n - i]; a[n - i] = x; i++; } } }