def pack_bits(bits):
    """convert a bit (bool or int) tuple into a int"""
    packed = 0
    level = 0
    for bit in bits:
        if bit:
            packed += 2 ** level
        level += 1
    return packed
