Advertisement
here2share

# IntList2Base.py

Jun 4th, 2022
1,228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. # IntList2Base.py
  2.  
  3. def IntList2Base(num, base=5): # because int(str,base) only reads one byte at a time
  4.     def bbb(num, base, i=1):
  5.         q=num/base
  6.         r=num%base
  7.         if (q == 0):
  8.             return (str(r), i)
  9.         else:
  10.             s,i = bbb(q, base)
  11.             return (s + str(r), i+1)
  12.     s,i = bbb(num,base)
  13.     return s + '0'*(len(str(base*num/9))-len(s)-1) # ??? had to fix this line vs original copy
  14.  
  15. theList = [0,11,100,782,1000,1222] # the list of numbers you want converted to base b
  16.  
  17. print theList
  18. print [IntList2Base(x,5) for x in theList]
  19.  
  20. print [IntList2Base(x,99) for x in theList]
  21.  
  22. ['0', '11', '110', '735', '1010', '1234']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement