Created
January 17, 2025 18:08
-
-
Save FAReTek1/1e5e13b5aff4e1025731240c344b28ae to your computer and use it in GitHub Desktop.
basic script to convert base (ints only)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_base(val, og_digits="0123456789", new_digits="0123456789"): | |
og_digits, new_digits = list(og_digits), list(new_digits) | |
og_base, new_base = len(og_digits), len(new_digits) | |
b10 = 0 | |
val = str(val) | |
for i, digit in enumerate(val): | |
b10 += og_digits.index(digit) * og_base ** (len(val) - i - 1) | |
ret = '' | |
while b10 >= 1: | |
ret = f"{new_digits[int(b10 % new_base)]}{ret}" | |
b10 /= new_base | |
return ret |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment