public static int byteArrayToInt(final byte[] byteArray, final int startPos, final int length) {
		if (byteArray == null) {
			throw new IllegalArgumentException("Parameter 'byteArray' cannot be null");
		}
		if (length <= 0 || length > 4) {
			throw new IllegalArgumentException("Length must be between 1 and 4. Length = " + length);
		}
		if (startPos < 0 || byteArray.length < startPos + length) {
			throw new IllegalArgumentException("Length or startPos not valid");
		}
		int value = 0;
		for (int i = 0; i < length; i++) {
			value += (byteArray[startPos + i] & 0xFF) << 8 * (length - i - 1);
		}
		return value;
	}
public static int byteArrayToInt ( final byte [ ] byteArray , final int startPos , final int length ) { if ( byteArray == null ) { throw new IllegalArgumentException ( "Parameter 'byteArray' cannot be null" ) ; } if ( length <= 0 || length > 4 ) { throw new IllegalArgumentException ( "Length must be between 1 and 4. Length = " + length ) ; } if ( startPos < 0 || byteArray . length < startPos + length ) { throw new IllegalArgumentException ( "Length or startPos not valid" ) ; } int value = 0 ; for ( int i = 0 ; i < length ; i ++ ) { value += ( byteArray [ startPos + i ] & 0xFF ) << 8 * ( length - i - 1 ) ; } return value ; }
Method used to convert byte array to int

@param byteArray
byte array to convert
@param startPos
start position in array in the
@param length
length of data
@return int value of byte array