I
I
Igor Nistakov2015-06-11 12:33:39
Informatics
Igor Nistakov, 2015-06-11 12:33:39

What are the ways to translate number systems?

Is there any universal way to translate numbers from one number system to another? Or for the speed of translation, some kind of easy way. Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
bobrovskyserg, 2015-06-11
@belloni

There are standard and bicycle ways.
For example, the standard python function int, which takes a string argument, can take a base as an optional second:
The bicycle method is also simple:

def to_str(n, radix):
    l = []
    while n:
        n, d = divmod(n, radix)
        l.append("0123456789ABC...Z"[d])
    return ''.join(reversed(l))

print(to_str(12345, 10))

Which one is universal, which one is light - decide for yourself.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question