Skip to content

Instantly share code, notes, and snippets.

@nazariyv
Created November 26, 2022 18:22
Show Gist options
  • Save nazariyv/c20f6bcdd91e7803c2d34224cb2e766e to your computer and use it in GitHub Desktop.
Save nazariyv/c20f6bcdd91e7803c2d34224cb2e766e to your computer and use it in GitHub Desktop.
Converts number n to base b
def number_to_base(n, b):
if n == 0:
return [0]
digits = []
while n:
digits.append(int(n % b))
n //= b
return digits[::-1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment