Quotient and Remainder to Number Base
From ProofWiki
Contents |
[edit] Theorem
Let
be an integer.
Let n be expressed in base b:
i.e.
Then:
where:
-
denotes the floor function;
-
denotes the modulo operation.
[edit] General Result
where
.
[edit] Proof
From the Quotient-Remainder Theorem, we have:
where
.
We have that:
| n | = |
| ||||
| = |
| |||||
| = |
|
Hence we can express n = qb + r where:
-
- r = r0
where
.
The result follows from the definition of the modulo operation.
[edit] Proof of General Result
Follows directly by induction on s.
[edit] Example
This result is often[1] 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:
| = | 09 | which gives us the day | |||
| = | 201002 | which we use as input into the next pass | |||
| = | 02 | which gives us the month | |||
| = | 2010 | which gives us the year. |
[edit] Notes
- ↑ So often, in some business applications, that the author of this page is utterly sick of it, truth be told.

