Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I work with base 5 numbers in Python? [duplicate]

Tags:

python

math

Possible Duplicate:
convert integer to a string in a given numeric base in python

I want to work with base 5 numbers, or any other non standard base for that matter.

I found out int('123', 5) works, but I need to go the other way around.

Should I write my own number class to accomplish this?

Maybe I'm just thinking in the wrong direction...

like image 505
Pepijn Avatar asked Feb 28 '23 13:02

Pepijn


1 Answers

def to_base_5(n):
    s = ""
    while n:
        s = str(n % 5) + s
        n /= 5
    return s
like image 50
John La Rooy Avatar answered Mar 10 '23 20:03

John La Rooy