mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
22 lines
400 B
Python
22 lines
400 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# author: bt3gl
|
|
|
|
|
|
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]
|