Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # IntList2Base.py
- def IntList2Base(num, base=5): # because int(str,base) only reads one byte at a time
- def bbb(num, base, i=1):
- q=num/base
- r=num%base
- if (q == 0):
- return (str(r), i)
- else:
- s,i = bbb(q, base)
- return (s + str(r), i+1)
- s,i = bbb(num,base)
- return s + '0'*(len(str(base*num/9))-len(s)-1) # ??? had to fix this line vs original copy
- theList = [0,11,100,782,1000,1222] # the list of numbers you want converted to base b
- print theList
- print [IntList2Base(x,5) for x in theList]
- print [IntList2Base(x,99) for x in theList]
- ['0', '11', '110', '735', '1010', '1234']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement