aboutsummaryrefslogtreecommitdiffstats
path: root/util/string/cast.py
blob: 47425494c06c08fe8ec8118fcfe25aa2ac361796 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
print 'static const ui8 SAFE_LENS[4][15] = {'

 
def nb(n, b):
    if n == 0:
        return [0]

    digits = []

    while n:
        digits.append(int(n % b))
        n /= b

    return digits[::-1]


for p in (1, 2, 4, 8):
 
    def it1():
        for base in range(2, 17):
            m = 2 ** (8 * p) - 1

            yield len(nb(m, base)) - 1

    print '     {0, 0, ' + ', '.join(str(x) for x in it1()) + '},'

print '};'