public static int byteArrayToInt(final byte[] src, final int srcPos, final int dstInit, final int dstPos,
            final int nBytes) {
        if (src.length == 0 && srcPos == 0 || 0 == nBytes) {
            return dstInit;
        }
        if ((nBytes - 1) * 8 + dstPos >= 32) {
            throw new IllegalArgumentException("(nBytes-1)*8+dstPos is greater or equal to than 32");
        }
        int out = dstInit;
        for (int i = 0; i < nBytes; i++) {
            final int shift = i * 8 + dstPos;
            final int bits = (0xff & src[i + srcPos]) << shift;
            final int mask = 0xff << shift;
            out = (out & ~mask) | bits;
        }
        return out;
    }
public static int byteArrayToInt ( final byte [ ] src , final int srcPos , final int dstInit , final int dstPos , final int nBytes ) { if ( src . length == 0 && srcPos == 0 || 0 == nBytes ) { return dstInit ; } if ( ( nBytes - 1 ) * 8 + dstPos >= 32 ) { throw new IllegalArgumentException ( "(nBytes-1)*8+dstPos is greater or equal to than 32" ) ; } int out = dstInit ; for ( int i = 0 ; i < nBytes ; i ++ ) { final int shift = i * 8 + dstPos ; final int bits = ( 0xff & src [ i + srcPos ] ) << shift ; final int mask = 0xff << shift ; out = ( out & ~ mask ) | bits ; } return out ; }
<p>
Converts an array of byte into an int using the default (little endian, Lsb0) byte and bit
ordering.
</p>

@param src the byte array to convert
@param srcPos the position in {@code src}, in byte unit, from where to start the
conversion
@param dstInit initial value of the destination int
@param dstPos the position of the lsb, in bits, in the result int
@param nBytes the number of bytes to convert
@return an int containing the selected bits
@throws NullPointerException if {@code src} is {@code null}
@throws IllegalArgumentException if {@code (nBytes-1)*8+dstPos >= 32}
@throws ArrayIndexOutOfBoundsException if {@code srcPos + nBytes > src.length}