mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-30 12:46:11 -04:00
17 lines
335 B
Python
17 lines
335 B
Python
def convert_to_any_base(base: int, num: int) -> str:
|
|
|
|
if num == 0:
|
|
return "0"
|
|
|
|
n = abs(num)
|
|
result = ""
|
|
|
|
while n:
|
|
result += str(n % base)
|
|
n //= base
|
|
|
|
if num < 0:
|
|
result += '-'
|
|
|
|
return result[::-1]
|