This algorithm converts a base c number into a base b number. Parameters c and b are arbitrary are not constrained by any bounds. The input n is a list and the output is a list.
Python, 7 lines
1 2 3 4 5 6 7
mod = lambda n,m: n%m def baseExpansion(n,c,b): i = len(n) base10 = sum([pow(c,i-k-1)*n[k] for k in range(i)]) j = int(ceil(log(base10 + 1,b))) baseExpanded = [mod(base10//pow(b,j-p),b) for p in range(1,j+1)] return baseExpanded
>>> baseExpansion([1,2,3],5,3) [1,1,0,2]
Tags: base, base16, base2, base_conversion, base_expansion, conversion, lists, numbers, number_theory, python
This recipe doesn't actually work.
Oh sorry, the input is not a string. It is a list.
@Steven Try this for a string
I have redone the algorithm so you can input and output a string