##### $\mathfrak{Mini}$ $\mathbb{Wiki}$

• No tags, yet

1. June 2020

# Basis Representation

Let $n$ be a positive number in decimal system and $k$ be the basis in which $n$ will be represented. The following code give us the representation of $n$ in basis $k$.

#!/usr/bin/python

def representation(n, k):
(q, r) = (n // k, n % k)

# print(str(n) + " = " + str(k) + " * " + str(q) + " + " + str(r))
if q == 0:
return [r]
else:
return representation(q, k) + [r]

Example: Let $n = 383$ and $k=4$.

n = 383
k = 4

print(''.join(map(str, representation(n, k))))

The solution is $11333$.