Each natural number is most commonly written in
decimal form (or base
),
where
are the digits. (Without
loss of generality we may assume that the leading digit
is non-zero.) This representation
is unique. (In spite of the fact that the decimal representation of a
real number is not unique -
.)
Similarly, each natural number can be written
(uniqely) in a binary expansion (or base
),
where
are the bits. The binary
representation of
is written as
. Clearly,
is even if and only if
. To find the binary expansion of a natural
number, perform the following steps.
- (1)
- Find the ``leading bit''
by determining the largest
power of
less than or equal to
. Call this power
and let
.
- (2)
- Subtract this power from
and replace
by this difference.
- (3)
- If the result is non-zero, go to step
1; otherwise, stop.
This determines all the non-zero bits
in the binary representation of
. The
other bits are 0.
More generally, let us fix an integer
.
Each natural number can be written in an
-ary expansion
where
are the
-ary digits.
Again, the
-ary representation of
is written as
. Clearly,
if and only if
.
To find the
-ary expansion of a natural
number, perform the following steps.
- (1)
- Find
by determining the largest
power of
less than or equal to
. Call this power
.
- (2)
- Find the largest positive integer multiple of
this power which is less than or equal to
. This multiple
will be the
-th digit
.
- (3)
- Subtract
from
and replace
by this difference.
- (4)
- If the result is non-zero, go to step
1; otherwise, stop.
Example 1.3.3
Convert
from binary to
-ary.
In decimal (or ``
-ary''),
is
In
-ary,
Subsections
David Joyner
2007-09-03