def pack(bits):
    """Packs the bits into an integer, LSB-first."""

    if isinstance(bits, list):
        acc = 0
        for bit in reversed(bits):
            acc <<= 1
            if bit:
                acc += 1
        return acc
    else:
        return int(bits)