Return integer concatenating integer chunks of r > 0 bit-length.

    >>> pack([0, 1, 0, 1, 0, 1], 1)
    42

    >>> pack([0, 1], 8)
    256

    >>> pack([0, 1], 0)
    Traceback (most recent call last):
        ...
    ValueError: pack needs r > 0

def pack(chunks, r=32):
    """Return integer concatenating integer chunks of r > 0 bit-length.

    >>> pack([0, 1, 0, 1, 0, 1], 1)
    42

    >>> pack([0, 1], 8)
    256

    >>> pack([0, 1], 0)
    Traceback (most recent call last):
        ...
    ValueError: pack needs r > 0
    """
    if r < 1:
        raise ValueError('pack needs r > 0')

    n = shift = 0

    for c in chunks:
        n += c << shift
        shift += r

    return n