Integer Representations
Theorem 1
- For any integer
(the base) and any positive integer n, there is a unique representation:
where:
is an integer (the highest power of in the representation). are digits, each satisfying . (so the first digit is not zero, ensuring uniqueness).
💡
Theorem 1 is called the base b expansion of n
Expansions
- Decimal: b = 10
- Binary : b = 2
- hexadecimal: b = 16
- Octal: b = 8
Base conversion
- First, divide n by b to obtain a quotient and remainder, that is,
- The remainder,
, is the rightmost digit in the base b expansion of n. Next, divide by b to obtain
is the second digit from the right in the base b expansion of n - Continue this process until we obtain a quotient equal to zero.

Algorithm

Conversion between 2, 16 and 8 expansions
- Each octal digit corresponds to a block of three binary digits
- Each hexadecimal digit corresponds to a block of four binary digits
Algorithms for Integer Operations
✅
The algorithms for performing operations with integers using their binary expansions are extremely important in computer arithmetic
Throughout this discussion, suppose that the binary expansions of a and b are
so that a and b each have n bits
Addition algorithm
- To add a and b, first add their rightmost bits. This gives
- where
is the rightmost bit (LSB) in the binary expansion of a + b is the carry, which is either 0 or 1
- Then add the next pair of bits and the carry,
- where
is the next bit (from the right) in the binary expansion of a + b is carry
- Continue this process
- At the last stage,
- Then, the leading bit of the sum is
✅

Multiplication algorithm
- Using the distributive law, we see that
- We first note that:
if if
- Each time we multiply a term by 2, we shift its binary expansion one place to the left and add a zero at the tail end of the expansion:
- Consequently, we can get
by shifting the binary expansion of abj j places to the left, that
- Finally, we get
by adding the n integers , j = 0, 1, 2, ... , n − 1.
- Pseudocode

Algorithm for DIV and MOD

- This algorithm takes
bit operations
Modular Exponentiation
- How to find efficiently without using an excessive amount of memory for
- Some thought,
- It is impractical to first compute
and then find its remainder when divided by m, because can be a huge number - We can apply Corollary 2 of Theorem 5 at
[4.1] Divisibility and Modularwhich is
- It is impractical to first compute
Then, we have (Recall that
However, this approach is impractical because it requires n − 1 multiplications of integers and n might be huge.
Fast modular exponentiation algorithm
- Note that, If we use the base 2 expansion of n, then
- This shows that to compute
, we need only compute the values of - The algorithm successively finds
, , , ... , and - multiplies together those terms
where

Cantor Expansion
Definition
A Cantor expansion represents a non-negative integer as
where
This representation is also known as the factorial number system.
Properties
1. Uniqueness
Every non-negative integer has a unique Cantor expansion.
2. Mixed radix system
Cantor expansion is not a fixed-base system. The radix at position
3. Bounded digits
Each coefficient has a strict bound:
Finding the Cantor Expansion
Algorithm
Given an integer
- Find the largest
such that - Compute
- Update
- Repeat for
Example
Find the Cantor expansion of
Why Cantor Expansion Works
Because
this guarantees:
- No overlap between representations
- Each sequence
maps to a distinct integer