A working Python code is needed, which translates any number from any number system to another given (any) number system. (from 0 to 32 can be both the original s / s, and received) Input format:

Number (For example: AA16342F)

Initial number system (16)

Numeral system to which we translate (8)

The output of the received number (25205432057)

Closed due to the fact that the essence of the issue is incomprehensible by the participants: Vladimir Martyanov , Alexey Shimansky , Ruslan_K , Bald , Kromster 26 Dec '16 at 5:00 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    You can like this:

    def convert_base(num, to_base=10, from_base=10): # first convert to decimal number if isinstance(num, str): n = int(num, from_base) else: n = int(num) # now convert decimal to 'to_base' base alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ" if n < to_base: return alphabet[n] else: return convert_base(n // to_base, to_base) + alphabet[n % to_base] 

    Tests:

     In [41]: convert_base('AA16342F', from_base=16, to_base=8) Out[41]: '25205432057' In [42]: convert_base('111', from_base=2) Out[42]: '7' In [43]: convert_base(33, to_base=16) Out[43]: '21' In [44]: convert_base(33333, to_base=20) Out[44]: '436D' In [45]: convert_base(3333333, to_base=20) Out[45]: '10GD6D' 
    • Thank. This is what you need. - NightCry