def from_base(base, num):
    """Decode a big-endian iterable of digits in the given base to a single
    positive integer.
    """
    out = 0
    for digit in num:
        if digit >= base or digit < 0:
            raise ValueError('invalid digit: %i' % digit)
        out *= base
        out += digit
    return out
