def bitmask(mask):
    """
    First element in `mask` is least-significant bit, last element is most-significant.
    """
    result = 0
    for index, x in enumerate(mask):
        result |= x << index
    return result
