Quotient and Remainder to Number Base

Theorem
Let $n \in \Z: n > 0$ be an integer.

Let $n$ be expressed in base $b$:
 * $\ds n = \sum_{j \mathop = 0}^m {r_j b^j}$

that is:
 * $n = \sqbrk {r_m r_{m - 1} \ldots r_2 r_1 r_0}_b$

Then:
 * $\ds \floor {\frac n b} = \sqbrk {r_m r_{m - 1} \ldots r_2 r_1}_b$
 * $n \bmod b = r_0$

where:
 * $\floor {\, \cdot \,}$ denotes the floor function;
 * $n \bmod b$ denotes the modulo operation.

Proof
From the Quotient-Remainder Theorem, we have:


 * $\exists q, r \in \Z: n = q b + r$

where $0 \le b < r$.

We have that:

Hence we can express $n = q b + r$ where:
 * $\ds q = \sum_{j \mathop = 1}^m {r_j b^{j - 1} }$
 * $r = r_0$

where:
 * $\ds \sum_{j \mathop = 1}^m {r_j b^{j - 1} } = \sqbrk {r_m r_{m - 1} \ldots r_2 r_1}_b$

The result follows from the definition of the modulo operation.

Example
This result is often used in computer algorithms for converting a date (in $yyyymmdd$ format) into a date object with separate day, month and year.

Performing the above "mod and div" operations on $20100209$, we get: