Beispiel #1
0
def numslice(x, start=None, stop=None, system=10):
    if start is None:
        start = 0
    if stop is None:
        stop = int(mlog.log(system)(x)) + 1
        
    if start < 0 and stop >= 0:
        start = int(mlog.log(system)(x)) + 1 + start
    elif stop < 0 and start >= 0:
        stop = int(mlog.log(system)(x)) + 1 + stop
    
    if stop < start:
        raise ValueError
    
    return nth(x, max(start, stop - 1), abs(start - stop), system)
Beispiel #2
0
def nth(x, n, digits=1, system=10):
    if n < 0:
        return int(x / (system ** (abs(n) - 1))) % system ** digits
    else:
        return int(
            x / (system ** int(mlog.log(system)(x) - n))
            ) % system ** digits