Here you can find the source of toBytes(int value, ByteOrder order)
public static byte[] toBytes(int value, ByteOrder order)
//package com.java2s; import java.nio.ByteOrder; public class Main { public static final int COUNT = 4; public static byte[] toBytes(int value, ByteOrder order) { byte[] result = new byte[COUNT]; if (ByteOrder.BIG_ENDIAN.equals(order)) { int i = COUNT - 1; do {/*from ww w. java2 s . c o m*/ result[i] = (byte) (value % 256); value = (int) (value / 256); --i; } while (i >= 0); } else { int i = 0; do { result[i] = (byte) (value % 256); value = (int) (value / 256); ++i; } while (i < COUNT); } return result; } }