Post History
#4: Post edited
If you have a non-negative integer $n$, and the base $b$ representation of $n$ is a sequence of digits, numbered from the right as $d_k\dots d_2d_1d_0$, then $d_i = \left\lfloor \frac{n}{b^i} ight floor \mod b$.- For example, decimal 10 is binary 1010 because:
- $$
d_3 = \left\lfloor \frac{10}{2^3} ight floor \pmod 2 = 1 \pmod 2 = 1- $$
- $$
d_2 = \left\lfloor \frac{10}{2^2} ight floor \pmod 2 = 2 \pmod 2 = 0- $$
- $$
d_1 = \left\lfloor \frac{10}{2^1} ight floor \pmod 2 = 5 \pmod 2 = 1- $$
- $$
d_0 = \left\lfloor \frac{10}{2^0} ight floor \pmod 2 = 10 \pmod 2 = 0- $$
- (For all $i > 3$, $d_i = 0$, because $10 < 2^i$.)
- This can be computed more efficiently using a loop or recursion, but this is the more succinct mathematical description.
- By the way, extending this formula to non-integers is straightforward—just continue the digit numbering past the point as $d_k\dots d_2d_1d_0.d_{-1}d_{-2}\dots$, and the formula is still valid, modulo the usual philosophical concerns about infinite sequences of digits.
- If you have a non-negative integer $n$, and the base $b$ representation of $n$ is a sequence of digits, numbered from the right as $d_k\dots d_2d_1d_0$, then $d_i = \left\lfloor \frac{n}{b^i} ight floor \bmod b$.
- For example, decimal 10 is binary 1010 because:
- $$
- d_3 = \left\lfloor \frac{10}{2^3} ight floor \bmod 2 = 1 \bmod 2 = 1
- $$
- $$
- d_2 = \left\lfloor \frac{10}{2^2} ight floor \bmod 2 = 2 \bmod 2 = 0
- $$
- $$
- d_1 = \left\lfloor \frac{10}{2^1} ight floor \bmod 2 = 5 \bmod 2 = 1
- $$
- $$
- d_0 = \left\lfloor \frac{10}{2^0} ight floor \bmod 2 = 10 \bmod 2 = 0
- $$
- (For all $i > 3$, $d_i = 0$, because $10 < 2^i$.)
- This can be computed more efficiently using a loop or recursion, but this is the more succinct mathematical description.
- By the way, extending this formula to non-integers is straightforward—just continue the digit numbering past the point as $d_k\dots d_2d_1d_0.d_{-1}d_{-2}\dots$, and the formula is still valid, modulo the usual philosophical concerns about infinite sequences of digits.
#3: Post edited
- If you have a non-negative integer $n$, and the base $b$ representation of $n$ is a sequence of digits, numbered from the right as $d_k\dots d_2d_1d_0$, then $d_i = \left\lfloor \frac{n}{b^i} \right\rfloor \mod b$.
- For example, decimal 10 is binary 1010 because:
- $$
- d_3 = \left\lfloor \frac{10}{2^3} \right\rfloor \pmod 2 = 1 \pmod 2 = 1
- $$
- $$
- d_2 = \left\lfloor \frac{10}{2^2} \right\rfloor \pmod 2 = 2 \pmod 2 = 0
- $$
- $$
- d_1 = \left\lfloor \frac{10}{2^1} \right\rfloor \pmod 2 = 5 \pmod 2 = 1
- $$
- $$
- d_0 = \left\lfloor \frac{10}{2^0} \right\rfloor \pmod 2 = 10 \pmod 2 = 0
- $$
- (For all $i > 3$, $d_i = 0$, because $10 < 2^i$.)
- This can be computed more efficiently using a loop or recursion, but this is the more succinct mathematical description.
By the way, extending this formula to non-integers is straightforward—continue the digit numbering past the point as $d_k\dots d_2d_1d_0.d_{-1}d_{-2}\dots$, and put a final floor around the formula: $d_i = \left\lfloor\left\lfloor \frac{n}{b^i} \right\rfloor \mod b\right\rfloor$.
- If you have a non-negative integer $n$, and the base $b$ representation of $n$ is a sequence of digits, numbered from the right as $d_k\dots d_2d_1d_0$, then $d_i = \left\lfloor \frac{n}{b^i} \right\rfloor \mod b$.
- For example, decimal 10 is binary 1010 because:
- $$
- d_3 = \left\lfloor \frac{10}{2^3} \right\rfloor \pmod 2 = 1 \pmod 2 = 1
- $$
- $$
- d_2 = \left\lfloor \frac{10}{2^2} \right\rfloor \pmod 2 = 2 \pmod 2 = 0
- $$
- $$
- d_1 = \left\lfloor \frac{10}{2^1} \right\rfloor \pmod 2 = 5 \pmod 2 = 1
- $$
- $$
- d_0 = \left\lfloor \frac{10}{2^0} \right\rfloor \pmod 2 = 10 \pmod 2 = 0
- $$
- (For all $i > 3$, $d_i = 0$, because $10 < 2^i$.)
- This can be computed more efficiently using a loop or recursion, but this is the more succinct mathematical description.
- By the way, extending this formula to non-integers is straightforward—just continue the digit numbering past the point as $d_k\dots d_2d_1d_0.d_{-1}d_{-2}\dots$, and the formula is still valid, modulo the usual philosophical concerns about infinite sequences of digits.
#2: Post edited
If you have a number $n$, and the base $b$ representation of $n$ is a sequence of digits, numbered from the right as $d_k\dots d_2d_1d_0$, then $d_i = \left\lfloor \frac{n}{b^i} ight floor \mod b$.- For example, decimal 10 is binary 1010 because:
- $$
- d_3 = \left\lfloor \frac{10}{2^3} \right\rfloor \pmod 2 = 1 \pmod 2 = 1
- $$
- $$
- d_2 = \left\lfloor \frac{10}{2^2} \right\rfloor \pmod 2 = 2 \pmod 2 = 0
- $$
- $$
- d_1 = \left\lfloor \frac{10}{2^1} \right\rfloor \pmod 2 = 5 \pmod 2 = 1
- $$
- $$
- d_0 = \left\lfloor \frac{10}{2^0} \right\rfloor \pmod 2 = 10 \pmod 2 = 0
- $$
- (For all $i > 3$, $d_i = 0$, because $10 < 2^i$.)
This can be computed more efficiently using a loop or recursion, but this is the more succinct mathematical description.
- If you have a non-negative integer $n$, and the base $b$ representation of $n$ is a sequence of digits, numbered from the right as $d_k\dots d_2d_1d_0$, then $d_i = \left\lfloor \frac{n}{b^i} ight floor \mod b$.
- For example, decimal 10 is binary 1010 because:
- $$
- d_3 = \left\lfloor \frac{10}{2^3} \right\rfloor \pmod 2 = 1 \pmod 2 = 1
- $$
- $$
- d_2 = \left\lfloor \frac{10}{2^2} \right\rfloor \pmod 2 = 2 \pmod 2 = 0
- $$
- $$
- d_1 = \left\lfloor \frac{10}{2^1} \right\rfloor \pmod 2 = 5 \pmod 2 = 1
- $$
- $$
- d_0 = \left\lfloor \frac{10}{2^0} \right\rfloor \pmod 2 = 10 \pmod 2 = 0
- $$
- (For all $i > 3$, $d_i = 0$, because $10 < 2^i$.)
- This can be computed more efficiently using a loop or recursion, but this is the more succinct mathematical description.
- By the way, extending this formula to non-integers is straightforward—continue the digit numbering past the point as $d_k\dots d_2d_1d_0.d_{-1}d_{-2}\dots$, and put a final floor around the formula: $d_i = \left\lfloor\left\lfloor \frac{n}{b^i} \right\rfloor \mod b\right\rfloor$.
#1: Initial revision
If you have a number $n$, and the base $b$ representation of $n$ is a sequence of digits, numbered from the right as $d_k\dots d_2d_1d_0$, then $d_i = \left\lfloor \frac{n}{b^i} \right\rfloor \mod b$. For example, decimal 10 is binary 1010 because: $$ d_3 = \left\lfloor \frac{10}{2^3} \right\rfloor \pmod 2 = 1 \pmod 2 = 1 $$ $$ d_2 = \left\lfloor \frac{10}{2^2} \right\rfloor \pmod 2 = 2 \pmod 2 = 0 $$ $$ d_1 = \left\lfloor \frac{10}{2^1} \right\rfloor \pmod 2 = 5 \pmod 2 = 1 $$ $$ d_0 = \left\lfloor \frac{10}{2^0} \right\rfloor \pmod 2 = 10 \pmod 2 = 0 $$ (For all $i > 3$, $d_i = 0$, because $10 < 2^i$.) This can be computed more efficiently using a loop or recursion, but this is the more succinct mathematical description.