Skip to content

Instantly share code, notes, and snippets.

@FAReTek1
Created January 17, 2025 18:08
Show Gist options
  • Save FAReTek1/1e5e13b5aff4e1025731240c344b28ae to your computer and use it in GitHub Desktop.
Save FAReTek1/1e5e13b5aff4e1025731240c344b28ae to your computer and use it in GitHub Desktop.
basic script to convert base (ints only)
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