Here you can find the source of toInt(byte[] bytes, ByteOrder order)
public static int toInt(byte[] bytes, ByteOrder order)
//package com.java2s; import java.nio.ByteOrder; public class Main { public static final int COUNT = 4; public static int toInt(byte[] bytes, ByteOrder order) { if (bytes == null) { throw new NullPointerException(); }// w w w. j av a2s . com byte[] temp = subArray(bytes, 0, COUNT); if (temp.length < COUNT) { temp = concat(new byte[COUNT - temp.length], temp); } int result = 0; int multiple = 1; if (ByteOrder.BIG_ENDIAN.equals(order)) { for (int i = COUNT - 1; i >= 0; i--) { result += temp[i] * multiple; multiple *= 256; } } else { for (int i = 0; i < COUNT; i++) { result += temp[i] * multiple; multiple *= 256; } } return result; } public static byte[] subArray(byte[] src, int pos, int length) { if (src == null || src.length < length - pos) { throw new IllegalArgumentException(); } byte[] result = new byte[length]; System.arraycopy(src, pos, result, 0, length); return result; } public static byte[] concat(byte[] src1, byte[] src2) { byte[] result = new byte[src1.length + src2.length]; System.arraycopy(src1, 0, result, 0, src1.length); System.arraycopy(src2, 0, result, src1.length, src2.length); return result; } }