def _extract_sub_bs(basis_state, qubits):
    """ Extract state of qubits in specified order, given in computational basis

    Since the input is in basis state, and the basis states of system only
    containing the sublist of qubits are a subset of the full basis,
    the state we look for is a basis state as well. This means we can
    return an integer here, instead of a full state.

    Example:
        >>> _extract_sub_bs(7, [3, 0, 1]) # 7 = 0b0111 -> 0b[1][0][3] = 0b110
        6

    :param basis_state: int
    :param qubits: Indices of qubits to extract from basis_state, in order of
        ascending significance.
    :return: Integer, representing state of qubits in the overall
        state basis_state.
    """
    return sum(1 << i
               for i in range(len(qubits))
               # if i-th apply qubit is set
               if basis_state & (1 << qubits[i]) != 0)