def build_binary_value(char_str, bits, alphabet) -> str:
    """
    This method converts a string char_str into binary, using n bits per
    character and decoding from the supplied alphabet or from ASCII when bits=7

    This is almost the inverse method to build_string in the decompress module.

    :param char_str: string.
    :param bits: number of bits per character.
    :param alphabet: Alphabet.
    :return: binary value.
    """
    if bits == 7:
        indices = [ord(char_) for char_ in char_str]
    else:
        indices = [alphabet.index(char_) for char_ in char_str]
    binary_char_list = ["{0:b}".format(index).zfill(bits) for index in indices]
    return ''.join(binary_char_list)