Figure 2.1:
method:
(a) 10 (b) 17 (c) 24 (d) 48
(e) 61 (f ) 93 (g) 125 (h) 186
Answer:
(a) 1010 (b) 10001 (c) 11000
(d) 110000 (e) 111101 (f ) 1011101
(g) 1111101 (h) 10111010
Answer:
(a) 1111 (b) 10101 (c) 11100
(d) 100010 (e) 101000 (f ) 111011
(g) 1000001 (h) 1001001
EXAMPLE 2-7
Add the following binary numbers:
(a) 11+11 (b) 100+10 (c) 111+11 (d) 110+100
Solution
The equivalent decimal addition is also shown for reference.
EXAMPLE 2-8
Perform the following binary subtractions:
(a) 11-01 (b) 11-10
Solution
(a) 11 3 (b) 11 3
−01 −1 −10 −2
10 2 01 1
No borrows were required in this example. The binary Number 01 is the
same as 1.
EXAMPLE 2-9
Subtract 011 from 101.
Solution
101 5
−011 −3
010 2
Let’s examine exactly what was done to subtract the two binary numbers
since a borrow is required. Begin with the right column as shown in Fig-
ure 2.2
Figure 2.2:
2.4. BINARY ARITHMETIC 33
EXAMPLE 2-10
Perform the following binary multiplications:
Figure 2.3:
4. Multiply
1101 × 1010
. Answer:
1101 × 1010 = 10000010
Answer:
(a) 100 (b) 100 (c) 1000
(d) 1101 (e) 1110 (f ) 11000
2.5. 1’S AND 2’S COMPLEMENTS OF BINARY NUMBERS 35
10.
(a) 11 × 11 (b) 100 × 10 (c) 111 × 101
(d) 1001 × 110 (e) 1101 × 110 (f ) 1110 × 1101
Answer:
(a) 1001 (b) 1000 (c) 100011
(d) 110110 (e) 10101001 (f ) 10110110
EXAMPLE 2-12
Find the 2’s complement of 10110010.
Solution
Solution
Answer:
(a) 010 (b) 001 (c) 0101
(d) 00101000 (e) 0001010 (f ) 11110
EXAMPLE 2-14
Express the decimal number -39 as an 8-bit number in the sign-magnitude,
1’s complement, and 2’s complement forms.
Solution
First, write the 8-bit number for +39.
00100111
10100111
In the 1’s complement form, -39 is produced by taking the 1’s complement
of +39 ()00100111.
11011000
In the 2’s complement form, -39 is produced by taking the 2’s complement
of +39 (00100111) as follows:
11011000 10 scomplement
+ 1
11011001 20 scomplement
EXAMPLE 2-15
Determine the decimal value of the signed binary number expressed in
sign-magnitude: 10010101.
Solution
The seven magnitude bits and their powers-of-two weights are as follows:
26 25 24 23 22 21 20
0 0 1 0 1 0 1
38 CHAPTER 2. NUMBER SYSTEMS, OPERATIONS, AND CODES
16 + 4 + 1 = 21
EXAMPLE 2-16
Determine the decimal value of the signed binary number expressed in
1’s complement:
(a) 00010111 (b) 11101000
Solution
(a) The bits and their powers-of-two weights for the positive numbers are as
follows:
−27 26 25 24 23 22 21 20
0 0 0 1 0 1 1 1
Summing the weights where there are 1s,
16 + 4 + 2 + 1 = +23
(b) The bits and their powers-of-two weights for the negative numbers are
as follows. Notice that the negative sign bit has a weight of −27 or -128.
−27 26 25 24 23 22 21 20
1 1 1 0 1 0 0 0
−128 + 64 + 32 + 8 = −24
−24 + 1 = -23
EXAMPLE 2-17
Determine the decimal value of the signed binary number expressed in
2’s complement:
(a) 01010110 (b) 10101010
2.6. SIGNED NUMBERS 39
Solution
(a) The bits and their powers-of-two weight for the positive number are as
follows:
−27 26 25 24 23 22 21 20
0 1 0 1 0 1 1 0
Summing the weights where there are 1s.
64 + 16 + 4 + 2 = +86
(b) The bits and their power-of-two weights for the negative number are as
follows. Notice that the negative sign bit has a weight os −27 = -128.
−27 26 25 24 23 22 21 20
1 0 1 0 1 0 1 0
Summing the weights where there are 1s,
−128 + 32 + 8 + 2 = -86
EXAMPLE 2-18
Convert the decimal number
3.248 × 104
Solution
Convert the decimal number to binary
0 100001101 11111011100000000000000
40 CHAPTER 2. NUMBER SYSTEMS, OPERATIONS, AND CODES
1. Express +19 and -19 in sign-magnitude, 1’s complement, and 2’s com-
plement.
Answer: See Figure 2.4.
Figure 2.4:
7. Express the decimal number -33 as an 8-bit binary number in the 1’s
complement system.
Answer: 1’s comp.: -33 = 11011110
8. Express the decimal number -46 as an 8-bit binary number in the 2’s
complement system.
Answer: 2’s comp.: -46 = 11010010
2.6. SIGNED NUMBERS 41
11. Express each decimal number as an 8-bit number in the 2’s complement
form:
(a) +12 (b) -68 (c) +101 (d) -125
Answer:
(a) 00001100 (b) 10111100
(c) 01100101 (d) 10000011
12. Determine the decimal value of each signed binary number in the 1’s
complement form:
(a) 10011001 (b) 01110100 (c) 10111111
Answer: (a) -102 (b) +116 (c) -64
2. Determine the decimal value of each signed binary number in the sign-
magnitude form:
(a) 10011001 (b) 01110100 (c) 10111111
42 CHAPTER 2. NUMBER SYSTEMS, OPERATIONS, AND CODES
3. Determine the decimal value of each signed binary number in the 2’s
complement form:
(a) 10011001 (b) 01110100 (c) 10111111
EXAMPLE 2-19
Add the signed numbers: 01000100, 00011011, 00001110, and 00010010.
Solution
The equivalent decimal additions are given for reference.
68 01000100
+ 27 + 00011011 Add 1st two numbers
95 01011111 1st sum
+ 14 + 00001110 Add 3rd number
109 01101101 2nd sum
+ 18 + 00010010 Add 4th number
127 01111111 F inal sum
EXAMPLE 2-20
Perform each of the following subtractions of the signed numbers:
(a) 00001000 - 00000011 (b) 00001100 - 11110111
(c) 11100111 - 00010011 (d) 10001000 - 11100010
Solution
Like in the other examples, the equivalent decimal subtractions are given for
reference.
2.7. ARITHMETIC OPERATIONS WITH SIGNED NUMBERS 43
EXAMPLE 2-21
Multiply the signed binary numbers: 01001101 (multiplicand)and 00000100
(multiplier) using the direct addition method.
Solution
Since both numbers are positive, they are in true form, and the product will
be positive. The decimal value of the multiplier is 4, so the multiplicand is
added to itself four times as follows:
01001101 1st time
+ 01001101 2nd time
10011010 P artial sum
+ 01001101 3rd time
11100111 P artial sum
+ 01001101 4th time
100110100 P roduct
44 CHAPTER 2. NUMBER SYSTEMS, OPERATIONS, AND CODES
Since the sign bit of the multiplicand is 0, it has no effect on the outcome.
All of the bits in the product are magnitude bits.
EXAMPLE 2-22
Multiply the signed binary numbers: 01010011 (multiplicand)and 11000101
(multiplier).
Solution
Step 1: The sign bit of the multiplicand is 0 and the sign bit of the multiplier
is 1. The sign bit of the product will be 1 (negative).
Step 2: Take the 2’s complement of the multiplier to put it in true form.
11000101 −→ 00111011
Step 3 and 4: The multiplication proceeds as follows. Notice that only the
magnitude bits are used in these steps.
1010011 M ultiplicand
× 0111011 M ultiplier
1010011 1st partial product
+ 1010011 2nd partial product
11111001 Sum of 1st and 2nd
+ 0000000 3rd partial product
011111001 Sum
+ 1010011 4th partial product
1110010001 Sum
+ 1010011 5th partial product
100011000001 Sum
+ 1010011 6th partial product
1001100100001 Sum
+ 0000000 7th partial product
1001100100001 F inal product
Step 5: Since the sign of the product is 1 as determined in step 1, take the
2’s complement of the product.
1001100100001 −→ 0110011011111
1 0110011011111
↑
2.7. ARITHMETIC OPERATIONS WITH SIGNED NUMBERS 45
EXAMPLE 2-23
Divide 01100100 by 00011001.
Solution
Step 1: The signs of both numbers are positive, so the quotient will positive.
The quotient is initially zero: 00000000.
Step 2: Subtract the divisor from the division using 2’s complement addition
(remember that final carries are discarded).
01100100 Dividen
+ 11100111 20 s complement of divisor
01001011 P ositive 1st partial remainder
Add 1 to quotient: 00000000 + 00000001 = 00000001.
Step 3: Subtract the divisor from the 1st partial remainder using 2’s com-
plement addition.
01001011 1st partial reminder
+ 11100111 20 s complement of divisor
00110010 P ositive 2nd partial reminder
Step 4: Subtract the divisor from the 2nd partial remainder using 2’s com-
plement addition.
00110010 2nd partial reminder
+ 11100111 20 s complement of divisior
00011001 P ositive 3rd partial reminder
Add 1 to quotient: 00000010 + 00000001 = 00000011.
Step 5: Subtract the divisor from the 3rd partial reminder using 2’s com-
plement addition.
00011001 3rd partial reminder
+11100111 20 s complement of divisor
00000000 Zero reminder
9. What is the sign of the product when two negative numbers are multi-
plied?
Answer: Sign of product is positive.
11. What is the sign of the quotient when a positive number is divided by
a negative number?
Answer: Sign of quotient is negative.
2.8. HEXADECIMAL NUMBERS 47
13. Convert each pair of decimal numbers to binary and add using the 2’s
complement form:
(1) 33 and 15 (b) 56 and -27 (c) -46 and 25 (d)-110 and -84
Answer:
(a) 00110000 (b) 00011101
(c) 11101011 (d) 100111110
EXAMPLE 2-24
Convert the following binary numbers to hexadecimal:
(a) 1100101001010111 (b) 111111000101101001
48 CHAPTER 2. NUMBER SYSTEMS, OPERATIONS, AND CODES
Solution
(a) 1100
| {z } 1010
| {z } 0101
| {z } 0111
| {z } (b) 0011
| {z } 1111
| {z } 0001
| {z } 0110
| {z } 1001
| {z }
↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
C A 5 7 = CA5716 3 F 1 6 9 = 3F16916
Two zeros have been added in part (b) to complete a 4-bit group at the left.
EXAMPLE 2-25
Determine the binary numbers for the following hexadecimal numbers:
(a) 10A416 (b) CF 8E16 (c) 974216
Solution
In part (a), the MSB is understood to have three zeros preceding it, thus
forming a 4-bit group.
EXAMPLE 2-26
Convert the following hexadecimal numbers to decimal:
(a) 1C16 (b) A8516
Solution
(a) 1 C
↓ ↓
z }| { z }| {
0001 1100 = 24 + 23 + 22 = 16 + 8 + 4 = 2810
(b) A 8 5
↓ ↓ ↓
z }| { z }| { z }| {
1010 1000 0101 = 211 + 29 + 27 + 22 + 20 = 2048 + 512 + 128 + 4 + 1 = 269310
EXAMPLE 2-27
Convert the following hexadecimal numbers to decimal:
(a) E516 (b) B2F 816
Solution
Recall from Figure 2.5 that letters A through F represent decimal numbers
10 through 15, respectively.
EXAMPLE 2-28
Convert the decimal number 650 to hexadecimal by repeated division by
16.
Solution
The solution is shown in Figure 2.6.
EXAMPLE 2-29
Add the following hexadecimal numbers:
(a) 2316 + 1616 (b) 5816 + 2216 (c) 2B16 + 8416 (d) DF16 + AC16
50 CHAPTER 2. NUMBER SYSTEMS, OPERATIONS, AND CODES
Figure 2.5:
Figure 2.6:
Solution
2.8. HEXADECIMAL NUMBERS 51
(a) 2316 right column : 316 + 616 = 310 + 610 = 910 = 916
+1616 lef t column : 216 + 116 = 2010 + 110 = 310 = 316
3916
(b) 5816 right column : 816 + 216 = 810 + 210 = 1010 = A16
+3316 lef t column : 516 + 216 = 510 + 210 = 710 = 716
7A16
(c) 2B16 right column : B16 + 416 = 1110 + 410 = 1510 = F16
+8416 lef t column : 216 + 816 = 210 + 810 = 1010 = A16
AF16
EXAMPLE 2-30
Subtract the following hexadecimal numbers:
(a) 8416 - 2A16 (b) C316 - 0B16
Solution
(a) 2A16 = 00101010
8416
+ D616 Add
1 5A16 Drop carry, as in 20 s complement addition
C316
+ F 516 Add
1 B816 Drop carry
6BD16 = 011010111101 = 21 0 + 29 + 27 + 25 + 24 + 23 + 22 + 20
= 1024 + 512 + 128 + 32 + 16 + 8 + 4 + 1 = 172510
Answer:
(a) 35 (b) 146 (c) 26 (d) 141
(e) 243 (f ) 235 (g) 1474 (g) 1792
EXAMPLE 2-31
Convert each of the following octal numbers to binary:
(a) 138 (b) 258 (c) 1408 (d) 75268
Solution
Solution
(a) |{z}
110 |{z}
101 (b) |{z}
101 |{z}
111 |{z}
001
↓ ↓ ↓ ↓ ↓
6 5 = 658 5 7 1 = 5718
(c) |{z}
100 |{z}
110 |{z}
011 |{z}
010 (d) |{z}
011 |{z}
010 |{z}
000 |{z}
100
↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
4 6 3 2 = 46328 3 2 0 4 = 32048
EXAMPLE 2-33
Convert each of the following decimal numbers to BCD:
(a) 35 (b) 98 (c) 170 (d) 2469
Solution
(a) 3 5 (b) 9 8
↓ ↓ ↓ ↓
z }| { z }| { z }| { z }| {
0011 0101 1001 1000
(c) 1 7 0 (d) 2 4 6 9
↓ ↓ ↓ ↓ ↓ ↓ ↓
z }| { z }| { z }| { z }| { z }| { z }| { z }| {
0001 0111 0000 0010 0100 0110 1001
EXAMPLE 2-34
Convert each of the following BCD codes to decimal:
(a) 10000110 (b) 001101010001 (c) 1001010001110000
Solution
| {z } 0110
(a) 1000 | {z } (b) 0011
| {z } 0101
| {z } 0001
| {z } (c) 1001
| {z } 0100
| {z } 0111
| {z } 0000
| {z }
↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
8 6 3 5 1 9 4 7 0
EXAMPLE 2-35
Add the following BCD numbers:
(a) 0011 + 0100 (b) 00100011 + 00010101
(c) 10000110 + 00010011 (d) 010001010000 + 010000010111
Solution
58 CHAPTER 2. NUMBER SYSTEMS, OPERATIONS, AND CODES
Note that in each case the sum in any 4-bit column does not exceed 9, and
the results are valid BCD numbers.
EXAMPLE 2-36
Solution
2.10. BINARY CODED DECIMAL (BCD) 59
(a) 1001 9
+ 0100 +4
1101 Invalid BCDnumber(> 9) 13
+ 0110 Add 6
0001
| {z } 0011
| {z } V alid BCD number
↓ ↓
1 3
(b) 1001 9
+ 1001 +9
1 0010 Invalid because of carry 18
+ 0110 Add 6
0001
| {z } 1000
| {z } V alid BCD number
↓ ↓
1 8
Answer:
(a) 00010000 (b) 00010011
(c) 00011000 (d) 00100001
(e) 00100101 (f ) 00110110
(g) 01000100 (h) 01010111
(i) 01101001 (j) 10011000
(k) 000100100101 (l) 000101010110
(a) 104 (b) 128 (c) 132 (d) 150 (e) 186
(f ) 210 (g) 359 (h) 547 (i) 1051
Answer:
Answer:
(a) 80 (b) 237 (c) 346 (d) 421
(e) 754 (f ) 800 (g) 978 (h) 1683
(i) 9018 (j) 6667
Answer:
EXAMPLE 2-37
(a) Convert the binary number 11000110 to Gray code.
(b) Convert the Gray code 10101111 to binary.
2.11. DIGITAL CODES 63
Figure 2.7:
Solution
The solution is as shown in Figure 2.7.
EXAMPLE 2-38
Determine the binary ASCII codes that are entered from the computer’s
keyboard when the following BASIC program statement is typed in. Also
express each code in hexadecimal.
20 P RIN T ”A = ”; X
Solution
The ASCII code for each symbol is found in Figure 2.8.
Symbol Binary Hexadecimal
2 0110010 3216
0 0110000 3016
Space 0100000 2016
P 1010000 5016
R 1010010 5216
I 1001001 4916
N 1001110 4E16
T 1010100 5416
Space 0100000 2016
” 0100010 2216
A 1000001 4116
= 0111101 3D16
” 0100010 2216
; 0111011 3B16
X 1011000 5816
64 CHAPTER 2. NUMBER SYSTEMS, OPERATIONS, AND CODES
Figure 2.8:
2.11. DIGITAL CODES 65
2. Determine the sequence of ASCII codes required for the following pro-
gram statement and express them in hexadecimal:
80 IN P U T Y
Answer: The sequence of codes for 80 INPUTY is
3816 3016 2016 4916 4E16 5016 5516 5416 2016 5916
3. Convert the following binary numbers to the Gray Code:
(a) 1100 (b) 1010 (c) 11010
Answer:
(a) 11002 = 1010 Gray (b) 10102 = 1111 Gray
(c) 110102 = 10111 Gray
4. Convert the following Gray codes to binary:
(a) 1000 (b) 1010 (c) 11101
Answer:
(a) 1000 Gray = 11112 (b) 1010 Gray = 11002
(c) 11101 Gray = 101102
5. What is the ASCII representation for each of the following characters?
Express each as a bit pattern and in hexadecimal notation.
(a) K (b) r (c) $ (d) +
Answer:
(a) 1001011 → 4B16 (b) 1110010 → 7216
(c) 0100100 → 2416 (d) 0101011 → 2B1 6
EXAMPLE 2-39
Assign the proper even parity bit to the following code groups:
(a) 1010 (b) 111000 (c) 101101
(d) 1000111001001 (e) 101101011111
Solution
Make the parity bit either 1 or 0 as necessary to make the total number of
1s even. The parity bit will be the left-most bit (bold).
EXAMPLE 2-40
An odd parity system receives the following code group: 10110, 11010,
110011, 110101110100, and 1100010101010. Determine which group, if any,
are in error.
Solution
Since odd parity is required, any group with an even number of 1s is incor-
rect. The following groups are in error: 110011 and 1100010101010.
EXAMPLE 2-41
Determine the Hamming code for the BCD number 1001 (data bits), us-
ing even parity.
Solution
Step 1: Find the number of parity bits required. Let p = 3. Then
2p = 23 = 8
d+p+1=4+3+1=8
Three parity bits are sufficient.
Figure 2.9:
Step 2: Construct a bit position table, as shown in Figure 2.9, and enter
the data bits. Parity bits are determined in the following steps.
Step 3: Determine the parity bits as follows:
Bit P1 checks bit positions 1,3,5, and 7 and must be a 0 for there to be
an even number of 1s (2) in this group.
Bit P2 checks bit positions 2,3,6, and 7 and must be a 0 for there to be
an even number of 1s (2) in this group.
Bit P3 checks bit positions 4,5,6, and 7 and must be a 0 for there to be
an even number of 1s (2) in this group.
Step 4: These parity bits are entered in Figure 2.9, and the resulting com-
bined code is 0011001.
EXAMPLE 2-42
Determine the Hamming code for the data bits 10110 using even parity.
Solution
Step 1: Determine the number of parity bits required. In this case the
number of data bits, d, is five. From the previous example we know that
p = 3 will not work. Try p = 4:
2p = 24 = 16
d + p + 1 = 5 + 4 + 1 = 10
Four parity bits are sufficient.
T otal code bits = 5 + 4 = 9
2.12. ERROR DETECTION AND CORRECTION CODES 69
Step 2: Construct a bit position table shown in Figure 2.10, and enter the
data bits. Parity bits are determined in the following steps. Notice that P4
is in bit position 8.
Figure 2.10:
Bit P1 checks bit positions 1,3,5,7, and 9 and must be a 1 for there to be an
odd number of 1s (3)in this group.
Bit P2 checks bit positions 2,3,7, and 7 and must be a 1 for there to be
an odd number of 1s (3)in this group.
Bit P3 checks bit positions 4,5,6, and 9 and must be a 1 for there to be
an odd number of 1s (3)in this group.
Step 4: These parity bits are entered in Figure 2.10, and the resulting
combined code is 101101110.
EXAMPLE 2-43
Assume that the code word in Example 2-41 (0011001)is transmitted and
that 0010001 is received. The receiver does not ”know” what was transmit-
ted and must look for proper parities to determine if the code is correct.
Designate any error that has occurred in transmission if even parity is used.
Solution
70 CHAPTER 2. NUMBER SYSTEMS, OPERATIONS, AND CODES
Figure 2.11:
Result: The error position code is 100 (binary four). This says that the
bit in position 4 is in error. It is a 0 and should be a 1. The corrected code
is 0011001, which agrees with the transmitted code.
EXAMPLE 2-44
The code 101101010 is received. Correct any errors. There are four parity
bits, and odd parity is used.
Solution
Figure 2.12:
Result: The error position code is 0111 (binary seven). This says that
the bit in position 7 is in error. The corrected code therefore 101101110.
1. Add an even parity bit to the 7-bit ASCII code for the letter K.
Answer: 01001011
Answer: Yes.
3. Determine the Hamming code for the BCD numbers 1000 using even
parity.
Answer: 1110000
6. The code 101111001 is received. Correct any error if odd parity is used.
Answer: The bit in position 0010(2) is in error. Correct to 111111000.
9. Add an even parity bit to the end of each of the following codes.
(a) 1010100 (b) 0100000 (c) 1110111 (d) 1000110
Answer:
(a) 10101001 (b) 01000001
(c) 11101111 (d) 10001101
10. How many parity bits are required for data bits 11010 using the Ham-
ming code?
Answer: Four parity bits
11. Create the Hamming code for the data bits 0011 using even parity.
Answer: 1 0 0 0 0 1 1 (parity bits are bold)
12. Determine which of the following even parity codes are in error:
(a) 100110010 (b) 011101010 (c) 10111111010001010
Answer: (b) is incorrect.
2.12. ERROR DETECTION AND CORRECTION CODES 73
13. Attach the proper even parity bit to each of the following bytes of data:
(a) 10100100 (b) 00001001 (c) 11111110
Answer:
(a) 110100100 (b) 000001001 (c) 111111110
14. Determine the odd-parity Hamming code for the data bits 11001.
Answer: 001010001
15. Correct any error in each of the following Hamming codes with odd
parity.
(a) 110100011 (b) 100001101
Answer: (a) 110100010 (b) 100000101
2. Determine the even-parity Hamming code for the data bit 1100.
3. Correct any error in each of the following Hamming codes with even
parity.
(a) 1110100 (b) 1000111