0% found this document useful (0 votes)
115 views

Binary Conversion

Uploaded by

Siraye Abirham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views

Binary Conversion

Uploaded by

Siraye Abirham
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

4.

3 Conversion Between Number Bases 169

4.3 Conversion Between Number Bases


Although the numeration systems discussed in the opening section were all base ten,
other bases have occurred historically. For example, the ancient Babylonians used 60
as their base. The Mayan Indians of Central America and Mexico used 20. In this
section we consider bases other than ten, but we use the familiar Hindu-
Arabic symbols. We will consistently indicate bases other than ten with a spelled-out
subscript, as in the numeral 43 five . Whenever a number appears without a subscript,
it is to be assumed that the intended base is ten. It will help to be careful how you
read (or verbalize) numerals here. The numeral 43 five is read “four three base five.”
(Do not read it as “forty-three,” as that terminology implies base ten and names a tot-
ally different number.)
For reference in doing number expansions and base conversions, Table 3 gives
the first several powers of some numbers used as alternative bases in this section.

TABLE 3 Selected Powers of Some Alternative Number Bases

Fourth Third Second First Zero


Power Power Power Power Power

TABLE 4 Base two 16 8 4 2 1


Base five 625 125 25 5 1
Base Ten Base Five Base seven 2401 343 49 7 1
0 0 Base eight 4096 512 64 8 1
1 1 Base sixteen 65,536 4096 256 16 1
2 2
3 3
4 4 We begin with the base five system, which requires just five distinct symbols,
5 10 0, 1, 2, 3, and 4. Table 4 compares base five and decimal (base ten) numerals for
6 11
the whole numbers 0 through 30. Notice that, while the base five system uses fewer
7 12
8 13 distinct symbols, it sometimes requires more digits to denote the same number.
9 14
10 20 EXAMPLE 1 Convert 1342 five to decimal form.
11 21 Referring to the powers of five in Table 3, we see that this number has one 125,
12 22
three 25s, four 5s, and two 1s, so
13 23
14 24
15 30
1342 five  1  125  3  25  4  5  2  1
16 31  125  75  20  2
17 32
18 33
 222 . 
19 34
20 40 A shortcut for converting from base five to decimal form, which is particularly
21 41 useful when you use a calculator, can be derived as follows. (We can illustrate this
22 42 by repeating the conversion of Example 1.)
23 43
24 44 1342 five  1  53  3  52  4  5  2
25 100
26 101
Now 5 can be factored out of the three quantities in parentheses, so
27 102 1342 five  1  52  3  5  4  5  2 .
28 103
29 104 Now, factoring another five out of the two “inner” quantities, we get
30 110
1342 five  1  5  3  5  4  5  2 .

An Addison-Wesley product. Copyright © 2004 Pearson Education, Inc.


170 CHAPTER 4 Numeration and Mathematical Systems

The inner parentheses around 1  5 are not needed since the product would be au-
tomatically done before the 3 is added. Therefore, we can write
1342 five  1  5  3  5  4  5  2 .
This series of products and sums is easily done as an uninterrupted sequence of
operations on a calculator, with no intermediate results written down. The same method
works for converting to base ten from any other base. The procedure is summarized
as follows.

Calculator Shortcut
To convert from another base to decimal form: Start with the first
digit on the left and multiply by the base. Then add the next digit, mul-
tiply again by the base, and so on. The last step is to add the last digit
Yin-yang The binary (base two) on the right. Do not multiply it by the base.
symbols of the I Ching, a 2000-
year-old Chinese classic, permute
into 8 elemental trigrams; 64 Exactly how you accomplish these steps depends on the type of calculator you
hexagrams are interpreted in
use. With some, only the digits, the multiplications, and the additions need to be en-
casting oracles.
tered, in order. With others, you may need to press the  key following each addi-
The basic symbol here is the
ancient Chinese “yin-yang,” in
tion of a digit. If you handle grouped expressions on your calculator by actually
which the black and the white entering parentheses, then enter the expression just as illustrated above and in the
enfold each other, each containing following example. (The number of left parentheses to start with will be two fewer
a part of the other. A kind of than the number of digits in the original numeral.)
duality is conveyed between
destructive (yin) and beneficial EXAMPLE 2 Use the calculator shortcut to convert 244314 five to deci-
(yang) aspects. Leibniz mal form.
(1646 –1716) studied Chinese
ideograms in search of a universal 244314 five  2  5  4  5  4  5  3  5  1  5  4
symbolic language and promoted  9334 
East-West cultural contact. He saw
parallels between the trigrams and EXAMPLE 3 Convert 497 from decimal form to base five.
his binary arithmetic.
The base five place values, starting from the right, are 1, 5, 25, 125, 625, and
Niels Bohr (1885 –1962),
so on. Since 497 is between 125 and 625, it will require no 625s, but some 125s, as
famous Danish Nobel laureate in
physics (atomic theory), adopted
well as possibly some 25s, 5s, and 1s. Dividing 497 by 125 determines the proper
the yin-yang symbol in his coat of number of 125s. The quotient is 3, with remainder 122. So we need three 125s. Next,
arms to depict his principle of the remainder, 122, is divided by 25 (the next place value) to find the proper num-
complementarity, which he ber of 25s. The quotient is 4, with remainder 22, so we need four 25s. Dividing 22
believed was fundamental to by 5 yields 4, with remainder 2. So we need four 5s. Dividing 2 by 1 yields 2 (with
reality at the deepest levels. Bohr remainder 0), so we need two 1s. Finally, we see that 497 consists of three 125s, four
also pushed for East-West 25s, four 5s, and two 1s, so 497  3442 five .
cooperation. More concisely, this process can be written as follows.
In its 1992 edition, The World
Book Dictionary first judged “yin- 497  125  3 Remainder 122
yang” to have been used enough
122  25  4 Remainder 22
to become a permanent part of our
ever changing language, assigning 22  5  4 Remainder 2
it the definition, “made up of 212 Remainder 0
opposites.”
497  3442 five

An Addison-Wesley product. Copyright © 2004 Pearson Education, Inc.


4.3 Conversion Between Number Bases 171

Check: 3442 five  3  125  4  25  4  5  2  1


 375  100  20  2
 497 . 

The calculator shortcut for converting from another base to decimal form in-
volved repeated multiplications by the other base. (See Example 2.) A shortcut for
converting from decimal form to another base makes use of repeated divisions by the
other base. Just divide the original decimal numeral, and the resulting quotients in
turn, by the desired base until the quotient 0 appears.

Photo not available EXAMPLE 4 Repeat Example 3 using the shortcut just described.

Remainder
5  497
5  99 2
5  19 4
5 3 4
0 3
Read the answer from the remainder column, reading from the bottom up:

497  3442 five . 

Woven fabric is a binary To see why this shortcut works, notice the following:
system of threads going
lengthwise (warp threads — tan in The first division shows that four hundred ninety-seven 1s are equivalent to
the diagram above) and threads ninety-nine 5s and two 1s. (The two 1s are set aside and account for the last
going crosswise (weft or woof). At digit of the answer.)
any point in a fabric, either warp
or weft is on top, and the variation The second division shows that ninety-nine 5s are equivalent to nineteen 25s
creates the pattern. and four 5s. (The four 5s account for the next digit of the answer.)
Nineteenth-century looms for
weaving operated using punched
The third division shows that nineteen 25s are equivalent to three 125s and
cards, “programmed” for pattern. four 25s. (The four 25s account for the next digit of the answer.)
The looms were set up with
The fourth (and final) division shows that the three 125s are equivalent to no
hooked needles, the hooks holding
625s and three 125s. The remainders, as they are obtained from top to bottom,
the warp. Where there were holes
in cards, the needles moved, the
give the number of 1s, then 5s, then 25s, then 125s.
warp lifted, and the weft passed
under. Where no holes were, the
The methods for converting between bases ten and five, including the shortcuts,
warp did not lift, and the weft was can be adapted for conversions between base ten and any other base.
on top. The system parallels the
on-off system in calculators and EXAMPLE 5 Convert 6343 seven to decimal form, by expanding in powers,
computers. In fact, these looms and by using the calculator shortcut.
were models in the development of
modern calculating machinery. 6343 seven  6  73  3  72  4  71  3  70
Joseph Marie Jacquard  6  343  3  49  4  7  3  1
(1752 –1823) is credited with
 2058  147  28  3
improving the mechanical loom
so that mass production of fabric  2236
was feasible.
Calculator shortcut: 6343 seven  6  7  3  7  4  7  3  2236 . 

An Addison-Wesley product. Copyright © 2004 Pearson Education, Inc.


172 CHAPTER 4 Numeration and Mathematical Systems

EXAMPLE 6 Convert 7508 to base seven.


Divide 7508 by 7, then divide the resulting quotient by 7, and so on, until a quo-
tient of 0 results.
Remainder

7  7508
7 1072 4
7  153 1
7  21 6
7 3 0
0 3

From the remainders, reading bottom to top, 7508  30614 seven . 


Because we are accustomed to doing arithmetic in base ten, most of us would
handle conversions between arbitrary bases (where neither is ten) by going from the
given base to base ten and then to the desired base, as illustrated in the next example.

EXAMPLE 7 Convert 3164 seven to base five.


First convert to decimal form.
3164 seven  3  73  1  72  6  71  4  70
 3  343  1  49  6  7  4  1
 1029  49  42  4
 1124
Next convert this decimal result to base five.
Remainder
TABLE 5
5  1124
Base Ten Base Two 5  224 4
(decimal) (binary)
5  44 4
0 0 5 8 4
1 1
2 10 5 1 3
3 11 0 1
4 100
5 101 From the remainders, 3164 seven  13444 five . 
6 110
7 111
8 1000
Computer Mathematics There are three alternative base systems that are
9 1001 most useful in computer applications. These are the binary (base two), octal (base
10 1010 eight), and hexadecimal (base sixteen) systems. Computers and handheld calcula-
11 1011 tors actually use the binary system for their internal calculations since that system
12 1100 consists of only two symbols, 0 and 1. All numbers can then be represented by elec-
13 1101
tronic “switches,” of one kind or another, where “on” indicates 1 and “off” indicates
14 1110
15 1111 0. The octal system is used extensively by programmers who work with internal
16 10000 computer codes. In a computer, the CPU (central processing unit) often uses the
17 10001 hexadecimal system to communicate with a printer or other output device.
18 10010 The binary system is extreme in that it has only two available symbols (0 and
19 10011
1); because of this, representing numbers in binary form requires more digits than in
20 10100
any other base. Table 5 shows the whole numbers up to 20 expressed in binary form.

An Addison-Wesley product. Copyright © 2004 Pearson Education, Inc.


4.3 Conversion Between Number Bases 173

Conversions between any of these three special base systems (binary, octal, and
hexadecimal) and the decimal system can be done by the methods already discussed,
including the shortcut methods.

EXAMPLE 8 Convert 110101 two to decimal form, by expanding in powers,


and by using the calculator shortcut.

110101 two  1  25  1  24  0  23  1  22


 0  21  1  20
 1  32  1  16  0  8  1  4  0  2
 1  1
 32  16  0  4  0  1
 53
Calculator shortcut:

110101 two  1  2  1  2  0  2  1  2  0  2  1


 53 . 

Trick or Tree? The octal EXAMPLE 9 Convert 9583 to octal form.


number 31 is equal to the decimal Divide repeatedly by 8, writing the remainders at the side.
number 25. This may be written as
Remainder
31 OCT  25 DEC 8  9583
Does this mean that Halloween 8 1197 7
and Christmas fall on the same 8  149 5
day of the year? 8  18 5
8 2 2
0 2

From the remainders, 9583  22557eight . 

The hexadecimal system, having base 16, which is greater than 10, presents a
new problem. Since distinct symbols are needed for all whole numbers from 0 up
to one less than the base, base sixteen requires more symbols than are normally
used in our decimal system. Computer programmers commonly use the letters A,
B, C, D, E, and F as hexadecimal digits for the numbers ten through fifteen,
respectively.

Converting Calculators A E X A M P L E 10 Convert FA5 sixteen to decimal form.


number of scientific calculators Since the hexadecimal digits F and A represent 15 and 10, respectively,
are available that will convert
between decimal, binary, octal,
and hexadecimal, and will also do FA5 sixteen  15  162  10  161  5  160
calculations directly in all of these  3840  160  5
separate modes.
 4005 . 

An Addison-Wesley product. Copyright © 2004 Pearson Education, Inc.


174 CHAPTER 4 Numeration and Mathematical Systems

E X A M P L E 11 Convert 748 from decimal form to hexadecimal form.


Use repeated division by 16.

Hexadecimal
Remainder notation
16  748
16  46 12 C
16  2 14 E
0 2 2

From the remainders at the right, 748  2EC sixteen . 

The decimal whole numbers 0 through 17 are shown in Table 6 along with their
equivalents in the common computer-oriented bases (two, eight, and sixteen). Con-
versions among binary, octal, and hexadecimal systems can generally be accom-
plished by the shortcuts explained below, and are illustrated in the next several
examples.

TABLE 6 Some Decimal Equivalents in the Common


Computer-Oriented Bases

Decimal Hexadecimal Octal Binary


(Base Ten) (Base Sixteen) (Base Eight) (Base Two)

0 0 0 0
1 1 1 1
2 2 2 10
3 3 3 11
4 4 4 100
5 5 5 101
6 6 6 110
7 7 7 111
8 8 10 1000
9 9 11 1001
10 A 12 1010
11 B 13 1011
12 C 14 1100
13 D 15 1101
14 E 16 1110
15 F 17 1111
16 10 20 10000
17 11 21 10001

The binary system is the natural one for internal computer workings because
of its compatibility with the two-state electronic switches. It is very cumbersome,
however, for human use, because so many digits occur even in the numerals for rel-
atively small numbers. The octal and hexadecimal systems are the choices of com-
puter programmers mainly because of their close relationship with the binary
system. Both eight and sixteen are powers of two. When conversions involve one

An Addison-Wesley product. Copyright © 2004 Pearson Education, Inc.


4.3 Conversion Between Number Bases 175

base that is a power of the other, there is a quick conversion shortcut available. For
TABLE 7
example, since 8  23, every octal digit (0 through 7) can be expressed as a 3-digit
Octal Binary binary numeral. See Table 7.

0 000
1 001
2 010
E X A M P L E 12 Convert 473 eight to binary form.
3 011 Replace each octal digit with its 3-digit binary equivalent. (Leading zeros can
4 100 be omitted only when they occur in the leftmost group.) Then combine all the binary
5 101 equivalents into a single binary numeral.
6 110
7 111 4 7 3 eight

100 111 011 two

By this method, 473 eight  100111011 two . 

Convert from binary form to octal form in a similar way. Start at the right and
break the binary numeral into groups of three digits. (Leading zeros in the leftmost
group may be omitted.)

TABLE 8 E X A M P L E 13 Convert 10011110 two to octal form.


Starting at the right, break the digits into groups of three. Then convert the
Hexadecimal Binary
groups to their octal equivalents.
0 0000
1 0001 10 011 110 two
2 0010
3 0011
4 0100 2 3 6 eight
5 0101
6 0110 Finally, 10011110 two  236 eight . 
7 0111
8 1000
9 1001
A 1010 Since 16  24, every hexadecimal digit can be equated to a 4-digit binary num-
B 1011 eral (see Table 8), and conversions between binary and hexadecimal forms can be
C 1100 done in a manner similar to that used in Examples 12 and 13.
D 1101
E 1110
F 1111
E X A M P L E 14 Convert 8B4Fsixteen to binary form.
Each hexadecimal digit yields a 4-digit binary equivalent.

8 B 4 Fsixteen

1000 1011 0100 1111 two

Combining these groups of digits, we see that

8B4Fsixteen  1000101101001111 two . 

An Addison-Wesley product. Copyright © 2004 Pearson Education, Inc.


176 CHAPTER 4 Numeration and Mathematical Systems

Several games and tricks are based on the binary system. For example, Table 9 can
be used to find the age of a person 31 years old or younger. The person need only tell
you the columns that contain his or her age. For example, suppose Kellen Dawson says
that her age appears in columns B and D only. To find her age, add the numbers from
the top row of these columns:
Kellen is 2  8  10 years old.
Do you see how this trick works? (See Exercises 68–71.)

TABLE 9

A B C D E
Several years ago, the Kellogg 1 2 4 8 16
Company featured a Magic Trick 3 3 5 9 17
Age Detector activity on specially 5 6 6 10 18
marked packages of Kellogg’s ® 7 7 7 11 19
Rice Krispies ® cereal. The trick 9 10 12 12 20
is simply an extension of the 11 11 13 13 21
discussion in the text. 13 14 14 14 22
15 15 15 15 23
Kellogg’s ® Rice Krispies ® and 17 18 20 24 24
characters Snap! ® Crackle! ® 19 19 21 25 25
and Pop! ® are registered 21 22 22 26 26
trademarks of Kellogg Company. 23 23 23 27 27
25 26 28 28 28
27 27 29 29 29
29 30 30 30 30
31 31 31 31 31

An Addison-Wesley product. Copyright © 2004 Pearson Education, Inc.

You might also like