Chapter 10
Chapter 10
Learning Objectives
The number 4728 means four thousands, seven hundreds, two tens, plus eight:
4728 = ( 4 × 1000 ) + ( 7 × 100 ) + ( 2 × 10 ) + 8
The decimal system is said to have a base , or radix, of 10. This means that each digit in the
number is multiplied by 10 raised to a power corresponding to that digit’s position:
83 = 1 0
( 8 × 10 ) + ( 3 × 10 )
4728 = 3 2 1 0
( 4 × 10 ) + ( 7 × 10 ) + ( 2 × 10 ) + ( 8 × 10 )
The same principle holds for decimal fractions, but negative powers of 10 are used. Thus, the decimal
fraction 0.256 stands for 2 tenths plus 5 hundredths plus 6 thousandths:
−1 −2 −3
0.256 = ( 2 × 10 ) + ( 5 × 10 ) + ( 6 × 10 )
A number with both an integer and fractional part has digits raised to both positive and negative
powers of 10:
442.256 = 2 1 0 −1 −2
( 4 × 10 ) + ( 4 + 10 ) + ( 2 × 10 ) + ( 2 × 10 ) + ( 5 × 10 )
−3
+ ( 6 × 10 )
In any number, the leftmost digit is referred to as the most significant digit, because it carries the
highest value. The rightmost digit is called the least significant digit. In the preceding decimal
number, the 4 on the left is the most significant digit and the 6 on the right is the least significant digit.
Table 10.1 shows the relationship between each digit position and the value assigned to that position.
Each position is weighted 10 times the value of the position to the right and one-tenth the value of the
position to the left. Thus, positions represent successive powers of 10. If we number the positions as
indicated in Table 10.1, then position i is weighted by the value 10i .
4 7 2 2 5 6
X = ∑ ( di × 10i ) (10.1)
i
One other observation is worth making. Consider the number 509 and ask how many tens are in the
number. Because there is a 0 in the tens position, you might be tempted to say there are no tens. But
there are in fact 50 tens. What the 0 in the tens position means is that there are no tens left over that
cannot be lumped into the hundreds, or thousands, and so on. Therefore, because each position
holds only the leftover numbers that cannot be lumped into higher positions, each digit position needs
to have a value of no greater than nine. Nine is the maximum value that a position can hold before it
flips over into the next higher position.
10.2 Positional Number Systems
In a positional number system, each number is represented by a string of digits in which each digit
position i has an associated weight r i , where r is the radix, or base, of the number system. The
general form of a number in such a system with radix r is
( … a3a2a1a0 . a − 1a − 2a − 3 … )
r
where the value of any digit ai is an integer in the range 0 ≤ ai < r . The dot between a0 and a − 1 is
called the radix point. The number is defined to have the value
3 2 1 0 −1 −2 −3
… + a3r + a2r + a1r + a0r + a − 1r + a − 2r + a − 3r +… (10.2)
=∑ ( ai × b i )
i
The decimal system, then, is a special case of a positional number system with radix 10 and with
digits in the range 0 through 9.
As an example of another positional system, consider the system with base 7. Table 10.2 shows the
weighting value for positions − 1 through 4. In each position, the digit value ranges from 0 through 6.
To avoid confusion, we will sometimes put a subscript on a number to indicate its base. For example,
8310 and 472810 are numbers represented in decimal notation or, more briefly, decimal numbers. The
digits 1 and 0 in binary notation have the same meaning as in decimal notation:
02 = 010
12 = 110
To represent larger numbers, as with decimal notation, each digit in a binary number has a value
depending on its position:
102 = 1 0
( 1 × 2 ) + ( 0 × 2 ) = 210
112 = 1 0
( 1 × 2 ) + ( 1 × 2 ) = 310
1002 = 2 1 0
( 1 × 2 ) + ( 0 × 2 ) + ( 0 × 2 ) = 410
and so on. Again, fractional values are represented with negative powers of the radix:
3 0 −1 −3
1001.101 = 2 + 2 + 2 +2 = 9.625 10
Y = ∑ ( bi × 2i ) (10.3)
i
10.4 Converting Between Binary and Decimal
It is a simple matter to convert a number from binary notation to decimal notation. In fact, we showed
several examples in the previous subsection. All that is required is to multiply each binary digit by the
appropriate power of 2 and add the results.
To convert from decimal to binary, the integer and fractional parts are handled separately.
Integers
For the integer part, recall that in binary notation, an integer represented by
bm − 1bm − 2 … b2b1b0 bi = 0or 1
Suppose it is required to convert a decimal integer N into binary form. If we divide N by 2, in the
decimal system, and obtain a quotient N 1 and a remainder R 0 , we may write
N = 2 × N 1 + R 0 R 0 = 0or 1
Next, we divide the quotient N 1 by 2. Assume that the new quotient is N 2 and the new remainder R 1 .
Then
N 1 = 2 × N 2 + R 1 R 1 = 0or 1
so that
2 1
N = 2 ( 2N 2 + R 1 ) + R 0 = ( N 2 × 2 ) + ( R 1 × 2 ) + R 0
If next
N 2 = 2N 3 + R 2
we have
3 2 1
N = ( N3 × 2 ) + ( R2 × 2 ) + ( R1 × 2 ) + R0
Because N > N 1 > N 2 … , continuing this sequence will eventually produce a quotient N m − 1 = 1 (except
for the decimal integers 0 and 1, whose binary equivalents are 0 and 1, respectively) and a remainder
R m − 2 , which is 0 or 1. Then
m−1 m −2 2 1
N = (1 × 2 ) + ( Rm − 2 × 2 ) + … + ( R2 × 2 ) + ( R1 × 2 ) + R0
which is the binary form of N. Hence, we convert from base 10 to base 2 by repeated divisions by 2.
The remainders and the final quotient, 1, give us, in order of increasing significance, the binary digits
of N. Figure 10.1 shows two examples.
Figure 10.1 Examples of Converting from Decimal Notation to Binary Notation for Integers
Fractions
For the fractional part, recall that in binary notation, a number with a value between 0 and 1 is
represented by
0 . b − 1b − 2b − 3 … bi = 0or 1
This expression suggests a technique for conversion. Suppose we want to convert the number
F ( 0 < F < 1 ) from decimal to binary notation. We know that F can be expressed in the form
−1 −1 −1
F =2 × (b−1 + 2 × (b−2 + 2 × (b−3 + … ) … ) )
If we multiply F by 2, we obtain,
−1 −1
2 × F = b−1 + 2 × (b−2 + 2 × (b−3 + … ) … )
From this equation, we see that the integer part of ( 2 × F ) , which must be either 0 or 1 because
0 < F < 1 , is simply b − 1 . So we can say ( 2 × F ) = b − 1 + F 1 , where 0 < F 1 < 1 and where
−1 −1 −1
F1 = 2 × (b−2 + 2 × (b−3 + 2 × (b−4 + … ) … ) )
To find b − 2 , we repeat the process. Therefore, the conversion algorithm involves repeated
multiplication by 2. At each step, the fractional part of the number from the previous step is multiplied
by 2. The digit to the left of the decimal point in the product will be 0 or 1 and contributes to the binary
representation, starting with the most significant digit. The fractional part of the product is used as the
multiplicand in the next step. Figure 10.2 shows two examples.
Figure 10.2 Examples of Converting from Decimal Notation to Binary Notation for Fractions
This process is not necessarily exact; that is, a decimal fraction with a finite number of digits may
require a binary fraction with an infinite number of digits. In such cases, the conversion algorithm is
usually halted after a prespecified number of steps, depending on the desired accuracy.
10.5 Hexadecimal Notation
Because of the inherent binary nature of digital computer components, all forms of data within
computers are represented by various binary codes. However, no matter how convenient the binary
system is for computers, it is exceedingly cumbersome for human beings. Consequently, most
computer professionals who must spend time working with the actual raw data in the computer prefer
a more compact notation.
What notation to use? One possibility is the decimal notation. This is certainly more compact than
binary notation, but it is awkward because of the tediousness of converting between base 2 and base
10.
Instead, a notation known as hexadecimal has been adopted. Binary digits are grouped into sets of
four bits, called a nibble. Each possible combination of four binary digits is given a symbol, as follows:
0000 = 0 0100 = 4 1000 = 8 1100 = C
0001 = 1 0101 = 5 1001 = 9 1101 = D
0010 = 2 0110 = 6 1010 = A 1110 = E
0011 = 3 0111 = 7 1011 = B 1111 = F
Because 16 symbols are used, the notation is called hexadecimal, and the 16 symbols are the
hexadecimal digits.
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
16 0001 0000 10
17 0001 0001 11
18 0001 0010 12
31 0001 1111 1F
2C16 = 1 0
( 216 × 16 ) + ( C16 × 16 )
= 1 0
( 210 × 16 ) + ( 1210 × 16 ) = 44
Thus, viewing hexadecimal numbers as numbers in the positional number system with base 16, we
have
Z = ∑ ( hi × 16i ) (10.4)
i
where 16 is the base and each hexadecimal digit hi is in the decimal range 0 ≤ hi < 15 , equivalent to
the hexadecimal range 0 ≤ hi ≤ F .
Hexadecimal notation is not only used for representing integers but also used as a concise notation
for representing any sequence of binary digits, whether they represent text, numbers, or some other
type of data. The reasons for using hexadecimal notation are as follows:
As an example of the last point, consider the binary string 110111100001. This is equivalent to
1101 1110 0001 = DE116
D E 1
This process is performed so naturally that an experienced programmer can mentally convert visual
representations of binary data to their hexadecimal equivalent without written effort.
10.6 Key Terms and Problems
Key Terms
base
binary
decimal
fraction
hexadecimal
integer
least significant digit
most significant digit
nibble
positional number system
radix
radix point
Problems
10.2 Order the numbers ( 1.1 ) 2 , ( 1.4 ) 10 , and ( 1.5 ) 16 from smallest to largest.
10.3 Perform the indicated base conversions:
a. 548 to base 5
b. 312 4 to base 7
c. 520 6 to base 7
d. 12212 3 to base 9
10.4 What generalizations can you draw about converting a number from one base to a power
2 2 3
of that base; e.g., from base 3 to base 9 ( 3 ) or from base 2 to base 4 ( 2 ) or base 8 ( 2 ) ?
10.5 Convert the following binary numbers to their decimal equivalents:
a. 001100
b. 000011
c. 011100
d. 111100
e. 101010
10.6 Convert the following binary numbers to their decimal equivalents:
a. 11100.011
b. 110011.10011
c. 1010101010.1
10.9 Prove that every real number with a terminating binary representation (finite number of
digits to the right of the binary point) also has a terminating decimal representation (finite
number of digits to the right of the decimal point).
10.10 Express the following octal numbers (number with radix 8) in hexadecimal notation:
a. 12
b. 5655
c. 2550276
d. 76545336
e. 3726755