Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { public static int bytesToInt(boolean asc, byte... bytes) { if (null == bytes) { throw new NullPointerException("bytes is null!"); } final int length = bytes.length; if (length > 4) { throw new IllegalArgumentException("Illegal length!"); } int result = 0; if (asc) for (int i = length - 1; i >= 0; i--) { result <<= 8; result |= (bytes[i] & 0x000000ff); } else for (int i = 0; i < length; i++) { result <<= 8; result |= (bytes[i] & 0x000000ff); } return result; } }