Sams Teach Yourself C++ in 21 Days

(singke) #1
In base 10 (decimal) math, you use ten symbols—the numerals 0, 1, 2, 3, 4, 5, 6, 7, 8,
and 9—to represent all numbers. How is the number ten represented?
You can imagine that a strategy could have evolved of using the letter A to represent ten;
or IIIIIIIIII could have been used to represent that idea. The Romans used X. The Arabic
system, which we use, makes use of position in conjunction with numerals to represent
values. The first (rightmost) column is used for ones, and the next column (to the left) is
used for tens. Thus, the number fifteen is represented as 15 (read “one, five”); that is, 1
ten and 5 ones.
Certain rules emerge, from which some generalizations can be made:


  1. Base 10 uses ten digits—the digits 0–9.

  2. The columns are powers of ten: 1s, 10s, 100s, and so on.

  3. If the third column is 100, the largest number you can make with two columns is
    99. More generally, with ncolumns you can represent from 0 to (10n-1). Thus, with
    three columns, you can represent from 0 to (10^3 -1) or 0-999.


Using Other Bases ..............................................................................................


It is not a coincidence that we use base 10; we have 10 fingers. You can imagine a differ-
ent base, however. Using the rules found in base 10, you can describe base 8:


  1. There are eight digits used in base 8—the digits 0–7.

  2. The columns are powers of 8: 1s, 8s, 64s, and so on.

  3. With ncolumns, you can represent 0 to 8n-1.
    To distinguish numbers written in each base, write the base as a subscript next to the
    number. The number fifteen in base 10 would be written as 15 10 and read as “one, five,
    base ten.”
    Thus, to represent the number 15 10 in base 8, you would write 17 8. This is read “one,
    seven, base eight.” Note that it can also be read “fifteen” as that is the number it contin-
    ues to represent.
    Why 17? The 1 means 1 eight, and the 7 means 7 ones. One eight plus seven ones equals
    fifteen. Consider fifteen asterisks:

    The natural tendency is to make two groups, a group of ten asterisks and another of five.
    This would be represented in decimal as 15 (1 ten and 5 ones). You can also group the
    asterisks as






808 Appendix A

29 0672327112_app_a.qxd 11/19/04 12:30 PM Page 808

Free download pdf