public static short binaryToShort(final boolean[] src, final int srcPos, final short dstInit, final int dstPos,
            final int nBools) {
        if (src.length == 0 && srcPos == 0 || 0 == nBools) {
            return dstInit;
        }
        if (nBools - 1 + dstPos >= 16) {
            throw new IllegalArgumentException("nBools-1+dstPos is greater or equal to than 16");
        }
        short out = dstInit;
        for (int i = 0; i < nBools; i++) {
            final int shift = i + dstPos;
            final int bits = (src[i + srcPos] ? 1 : 0) << shift;
            final int mask = 0x1 << shift;
            out = (short) ((out & ~mask) | bits);
        }
        return out;
    }
public static short binaryToShort ( final boolean [ ] src , final int srcPos , final short dstInit , final int dstPos , final int nBools ) { if ( src . length == 0 && srcPos == 0 || 0 == nBools ) { return dstInit ; } if ( nBools - 1 + dstPos >= 16 ) { throw new IllegalArgumentException ( "nBools-1+dstPos is greater or equal to than 16" ) ; } short out = dstInit ; for ( int i = 0 ; i < nBools ; i ++ ) { final int shift = i + dstPos ; final int bits = ( src [ i + srcPos ] ? 1 : 0 ) << shift ; final int mask = 0x1 << shift ; out = ( short ) ( ( out & ~ mask ) | bits ) ; } return out ; }
<p>
Converts binary (represented as boolean array) into a short using the default (little
endian, Lsb0) byte and bit ordering.
</p>

@param src the binary to convert
@param srcPos the position in {@code src}, in boolean unit, from where to start the
conversion
@param dstInit initial value of the destination short
@param dstPos the position of the lsb, in bits, in the result short
@param nBools the number of booleans to convert
@return a short containing the selected bits
@throws NullPointerException if {@code src} is {@code null}
@throws IllegalArgumentException if {@code nBools-1+dstPos >= 16}
@throws ArrayIndexOutOfBoundsException if {@code srcPos + nBools > src.length}