Sie sind auf Seite 1von 32

Chapter 2

Operations in Binary, Octal, and Hexadecimal Systems

his chapter begins with an introduction to arithmetic operations in binary, octal, and hexadecimal numbers. The tens-complement and nines-complements in the decimal system and the twos-complement and ones-complements in the binary system are discussed.

2.1 Binary System Operations


In this section we will discuss binary addition. We will defer binary subtraction until we introduce the twos and ones complements in a later section of this chapter. Binary multiplication and binary division is discussed in Chapter 9 in conjunction with shift registers. The addition of numbers in any numbering system is accomplished much the same manner as decimal addition, that is, the addition starts in the least significant position (right most position), and any carries are added in other positions to the left as it is done with the decimal system. The binary number system employs the numbers 0 and 1 only; therefore, the possible combinations of binary addition are: 0+0=0 0+1=1 1+0=1 1 + 1 = 0 with a carry of 1

We observe that in a binary addition the largest digit in any position is 1 , just as in the decimal addition the largest digit is 9 . Furthermore, the above combinations indicate that if the number of ones to be added in any column is odd, the sum digit for that column will be 1 , and if the number of ones to be added in any column is even, then the sum digit for that column will be zero. Also, a carry occurs whenever there are two or more ones to be added in any column. Example 2.1 Add the numbers (101101101)2 and (1110011)2 Solution: 1111111 101101101 1110011 111100000 + Carnes

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

2-1

Chapter 2 Operations in Binary, Octal, and Hexadecimal Systems Check:

Then,

(101101101)2 = (365)io (1110011)2 = (H5)io (111100000)2 = (365 + H5)10 = (480)


10

Example 2.2 Add the numbers (110110)2, (101001 ) 2 , (111000)2, (10101)2, and (100010)2 Solution: 11 11
lilil Carnes 110110 101001 111000 + 10101 100010J

Check:

11001110 (110110)2 = (54)10 (101001)2 = (41)io (111000)2 = (56)10

(10101)2 = (21)io (100010)2 = (34)10 Then, (llOOlllO)2 = (54 + 41 + 56 + 21 + 34)10 = (206)


10

2.2 Octal System Operations


The addition of octal numbers is also very similar to decimal numbers addition except that when the sum of two or more octal numbers exceeds seven, a carry occurs just as a carry occurs when

2-2
FPGAs

Digital Circuit Analysis and Design with an Introduction to CPLDs and Orchard Publications

Octal System Operations the sum of two or more decimal numbers exceeds nine. Table 2.1 summarizes the octal addition. This table can also be used for octal subtraction as it will be illustrated by Example 2.4. TABLE 2.1 Table for Addition and subtraction of octal numbers
0 0 1 2 3 4 5 6 7 1 1 2 3 4 5 6 7 10 2 2 3 4 5 6 7 10 11 3 3 4 5 6 7 10 11 12 4 4 5 6 7 10 11 12 13 7 10 11 12 13 14 5 5 6 6 6 7 10 11 12 13 14 15 7 7 10 11 12 13 14 15 16

When Table 2.1 above is used for addition, we first locate the least significant digit of the first number (augend) in the upper row of the table, and then we locate the least significant digit of the second number (addend) in the left most column of the table. The intersection of the augend with the addend gives the sum of these two numbers. We follow the same procedure for all other digits from right to left. Example 2.3 Add the numbers (3527)8 and (4167)8 Solution: 011 Carnes 3527] } + 4167 7716 Starting with the least significant digit column above, we add 7 with 7 and the table gives us 16 i.e., 6 with a carry of 1 . Next we add 6 and 2 , with a carry of 1 , or 6 and 3 , and the table gives us 11 i.e., 1 with a carry of 1 . Now we add 1 , 5 and 1 (carry) and we get 7 with no carry. Finally, we add 4 and 3 which gives 7 and no carry. As before, we can check the sum for correct-ness by converting the numbers to their equivalent decimal numbers. When Table 2.1 above is used for subtraction, we first find the least significant digit of the subtrahend (the smaller number) in the first row of the table. Then, in the same column, we locate the least significant digit of the minuend (the larger number). If the least significant digit of the minu-

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

2-3

Chapter 2 Operations in Binary, Octal, and Hexadecimal Systems end is less than the least significant digit of the subtrahend, a borrow occurs and from the num-bers 10 through 16 in the table we choose the one whose least significant digit matches the least significant digit of the minuend. We find the difference by going across to the left most column. We follow the same procedure for all other digits from right to left. We can use MATLAB conversin function base2dec(s,b) to convert the string number s of base b into its decimal (base 10) equivalent. b must be an integer between 2 and 36. For this example, x=base2dec('3527',8); y=base2dec('4167',8); z=base2dec('7716',8); v=x+y; fprintf(' \n');... fprintf('x=%5.0f \t',x); fprintf('y=%5.0f \t',y); fprintf('v=%5.0f \t',v);... fprintf('z=%5.0f \t',z); fprintf(' \n')

x=1879

y=2167

v=4046

z=4046

Example 2.4 Subtract (415)8 from (614)8 Solution: 614 415 177 The least significant digit of the subtrahend is 5 and we lcate it in the first row of Table 2.1. Going down that column where 5 appears, we choose 14 because the least significant digit of the minuend is 4 . The difference, 7 in this case with a borrow, appears across to the left most column. Next, we add the borrow to the next digit of the subtrahend, 1 in this case, so now we must subtract 2 from 1. Continuing we lcate 2 in the first row of the table and going down on the same column we choose 11 because the next digit of the minuend is 1, and again from the left most column we find that the difference is 7 with another borrow. Finally, we add that borrow to 4 and now we subtract 5 from 6 and this difference of 1 appears in the most significant position of the result with no borrow. Check with MATLAB: x=base2dec('614',8); y=base2dec('415',8); z=base2dec('177',8); v=x-y;... fprintf(' \n');... fprintf('x=%3.0f \t',x); fprintf('y=%3.0f \t',y); fprintf('v=%3.0f \t',v);... fprintf('z=%3.0f \t',z); fprintf(' \r)

x=396

y=269

v=127

z=127

2-4

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

Hexadecimal System Operations

2.3 Hexadecimal System Operations


Hexadecimal addition and subtraction is accomplished similarly to that of addition and subtraction with octal numbers except that we use Table 2.2. When Table 2.2 below is used for addition, we first locate the least significant digit of the first number (augend) in the upper row of the table, and then we locate the least significant digit of the second number (addend) in the left most col-umn of the table. The intersection of the augend with the addend gives the sum of these two numbers. We follow the same procedure for all other digits from right to left. TABLE 2.2 Table for Addition and subtraction of hexadecimal numbers
0 1 2 3 4 5 6 7 8 9 A B C D E F 1 2 3 4 5 6 7 8 9 A B C D E F 10 2 3 4 5 6 7 8 9 A B C D E F 10 11 3 4 5 6 7 8 9 A B C D E F 10 11 12 4 5 6 7 8 9 A B C D E F 10 11 12 13 5 6 7 8 9 A B C D E F 10 11 12 13 14 6 7 8 9 A B C D E F 10 11 12 13 14 15 7 8 9 A B C D E F 10 11 12 13 14 15 16 8 9 A B C D E F 10 11 12 13 14 15 16 17 9 A B C D E F 10 11 12 13 14 15 16 17 18 A B C D E F 10 11 12 13 14 15 16 17 18 19 B C D E F 10 11 12 13 14 15 16 17 18 19 1A C D E F 10 11 12 13 14 15 16 17 18 19 1A IB D E F 10 11 12 13 14 15 16 17 18 19 1A IB 1C E F F 10

10 11 11 12 12 13 13 14 14 15 16 17 18 19 1A IB 1C ID 15 16 17 18 19 1A IB 1C ID 1E

Example 2.5 Add the numbers (F347)16 and (E916)16 Solution: F347] y+ E916J 1DC5D Starting with the least significant digit column above, we add 7 with 6 and the table gives us D with no carry. Next, we add 4 and 1 and we get 5 with no carry. Now, we add 9 and 3 and we

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

2-5

Chapter 2 Operations in Binary, Octal, and Hexadecimal Systems get C with no carry. Finally, we add F and E and that gives ID. As before, we can check the for correctness by converting the numbers to their equivalent decimal numbers. Check with MATLAB:
x=base2dec('F347',16); y=base2dec('E916',16); z=base2dec('1DC5D',16); v=x+y;... fprintf(' \n');... fprintf('x=%6.0f \t',x); fprintf('y=%6.0f \t',y); fprintf('v=%6.0f \t',v);... fprintf('z=%6.0f \t',z); fprintf(' \n')

x=62279 Example 2.6

y=59670

v=121949

z=121949

Subtract (A9F8)16 from (D5C7) Solution: D5C7 A9F8 2BCF The subtraction begins by locating the least significant digit of the subtrahend, 8 in this case, in the first row of Table 2.2, and going down the same column we find 17 on the last row of the table. Going across to the left most column we find that the difference is F with a borrow. Next, because of the borrow, we reduce the digit C of the minuend to B and from it we subtract. The difference is found by locating F in the first row, going down the same column we find IB , and going across to the left most column we find that the difference is C with a borrow. Now, because of the previous borrow, we reduce 5 to 4 and subtracting 9 from it we find that the difference is B with another borrow. Finally, because of the previous borrow, we reduce D to C and we subtract A from it. The difference is 2 with no borrow. Check with MATLAB:
x=base2dec('D5C7',16); y=base2dec('A9F8',16); z=base2dec('2BCF',16); v=x-y;... fprintf(' \n');... fprintf('x=%3.0f \t',x); fprintf('y=%3.0f \t',y); fprintf('v=%3.0f \t',v);... fprintf('z=%3.0f \t',z); fprintf(' \r)

x=54727

y=43512

v=11215

z=11215

2.4 Complements of Numbers The subtraction operation is simplified by the use of the complements of numbers. For each base-b system there are two useful types of complements, the bs-complement, and the (b-l)s-complement. Accordingly, for the base-10 system we have the tens-complements and the nines-complements,

2-6
FPGAs

Digital Circuit Analysis and Design with an Introduction to CPLDs and Orchard Publications

Complements of Numbers for the base-2 we have the twos-complements and ones-complements, for the base-8 we have the eights-complements and sevens-complements, and for the base-16 we have the sixteens-complements and the fifteens-complements. 2.4.1 Tens-Complement The tens-complement of a number can be found by subtracting the first non-zero least significant digit and all zeros to the right of it from 10 ; then, we subtract all other digits from 9 . Example 2.7 Find the tens-complement of 23567 Solution: We first subtract 7 (lsd) from 10 and we get 3 . This is the lsd of the tens-complement. For the remainder part of the tens-complement, we subtract 6 , 5 , 3 , and 2 from 9 and we get 3 , 4 , 6 , and 7 respectively. Therefore, the tens-complement of 23567 is 76433 . Example 2.8 Find the tens-complement of 0.8642 Solution: We first subtract 2 (lsd) from 10 and all other digits from 9 . Therefore, the tens-complement of 0.8642 is 0.1358 . Example 2.9 Find the tens-complement of 37.562 Solution: We first subtract 2 (lsd) from 10 and all other digits from 9 . Therefore, the tens-complement of 37.562 is 62.438 . 2.4.2 Nines-Complement The nines-complement of a number can be found by subtracting every digit (lsd) of that number from 9 .

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

2-7

Chapter 2 Operations in Binary, Octal, and Hexadecimal Systems Example 2.10 Find the nines-complement of 23567 Solution: We subtract every digit of the given number from 9 and we find that the nines-complement of 23567 is 76432 . We observe that this complement is one less than 76433 which, as we found in Example 2.7, is the tens-complement of 23567 . This is always the case, that is, the nines-complement is always one less than the tens-complement. Alternately, we can add 1 to the nines-complement to get the tens-complement. Example 2.11 Find the nines-complement of 37.562 Solution: We subtract every digit of the given number from 9 and we find that the nines-complement of 23567 is 76432 .Therefore, the nines-complement of 37.562 is 62.437 . 2.4.3 Twos-Complement The twos-complement of a number can be found by leaving all the least significant zeros and the least significant one unchanged and then replacing all zeros with ones and all ones with zeros in all the other digits. Example 2.12 Find the twos-complement of 1101100 Solution: Starting from the right side of the given number we leave 100 unchanged and then for the remaining digits, i.e, 1101 we replace the ones with zeros and the zero with one. Therefore, the twos-complement of 1101100 is 0010100. Example 2.13 Find the twos-complement of 0.1011 Solution: We leave the lsd (last 1 ) unchanged and we replace the ones with zeros and the zero with

2-8
FPGAs

Digital Circuit Analysis and Design with an Introduction to CPLDs and Orchard Publications

Complements of Numbers Therefore, the twos-complement of 0.1011 is 0.0101. The leading 0 to the left of the binary point that separates the integer and fractional parts remains unchanged. Example 2.14 Find the twos-complement of 1101100.1011 Solution: We leave the lsd (last 1 ) unchanged and we replace the ones with zeros and the zeros with ones. Therefore, the twos-complement of 1101100.1011 is 0010011.0101 . 2.4.4 Ones-Complement The ones-complement of a number can be found by replacing all zeros with ones and all ones with zeros. Example 2.15 Find the ones-complement of 1101100 Solution: Replacing all ones with zeros and all zeros with ones we find that the ones-complement of 1101100 is 0010011 . We observe that this complement is one less than 0010100 which, as we found in Example 2.12, is the twos-complement of 1101100 . This is always the case, that is, the ones- complement is always one less than the twos-complement. Alternately, we can add 1 to the ones- complement to get the twos-complement. Example 2.16 Find the ones-complement of 0.1011 Solution: Replacing all ones with zeros and all zeros with ones we find that the ones-complement of 0.1011 is 0.0100. The leading 0 to the left of the binary point that separates the integer and fractional parts remains unchanged. Example 2.17 Find the ones-complement of 1101100.1011

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

2-9

Chapter 2 Operations in Binary, Octal, and Hexadecimal Systems Solution: Replacing all ones with zeros and all zeros with ones we find that the ones-complement of 1101100.1011 is 0010011.0100.

2.5 Subtraction with Tens- and Twos-Complements


We will assume that the numbers for the subtraction operation are both positive numbers. The subtraction operation using tens-complement or twos-complements is performed as follows: 1.Take the tens-complement or twos-complement of the subtrahend and add it to the minuend which remains unchanged. 2.Check the result (sum), and a. if an end carry occurs, discard it. b. if an end carry does not occur, take the tens-complement or twos-complement of the result (sum) and place a minus ( - ) sign in front of it. Example 2.18 Perform the subtraction (61435 - 02798)10 using the tens-complement method. Solution: Minuend = 61435 stays unchanged -> 61435 Subtrahend = 02798 take tens-complement -> 97202 Discard end carry -> 158637 Therefore, (61435 - 02798)10 = (58637)10 +

Example 2.19 Perform the subtraction (02798 - 61435)10 using the tens-complement method. Solution: Minuend = 02798 stays unchanged -> 027981 Subtrahend = 61435 take tens-complement -> 38565 j + No end carry -> 41363 Since there is no end carry, we take the tens-complement of the sum 41363 and we place a minus (-) sign in front of it resulting in -58637 . Therefore, (02798 - 61435)10 = (-58637)10.

2-10

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

Subtraction with Nines- and Ones-Complements Example 2.20 Perform the subtraction (1101100 - 1011011)2 using the twos-complement method. Solution: Minuend= 1101100 stays unchanged -> 11011001 Subtrahend = 1011011 take twos-complement -> 0100101 j + Discard end carry -> 10010001 Therefore, (1101100-1011011)2 = (0010001)2

Example 2.21 Perform the subtraction (1011011 - 1101100)2 using the twos-complement method. Solution: Minuend= 1011011 stays unchanged -> 10110111 Subtrahend = 1101100 take twos-complement -> 0010100 J + No end carry -^ 1101100 Since there is no end carry, we take the twos-complement of the sum 1101100 and we place a minus (-) sign in front of it resulting in -0010001. Therefore, (1011011 - 1101100)2 = (-0010001 ) 2 .

2.6 Subtraction with Nines- and Ones-Complements


We will assume that the numbers for the subtraction operation are both positive numbers. The subtraction operation using nines-complement or ones-complements is performed as follows: 1.Take the nines-complement or ones-complement of the subtrahend and add it to the minuend which remains unchanged. 2.Check the result (sum), and a. if an end carry occurs, add 1 - referred to as end around carry - to the lsd of the result (sum). b. if an end carry does not occur, take the nines-complement or ones-complement of the result (sum) and place a minus ( - ) sign in front of it.

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs

2-

11
Orchard Publications

Chapter 2 Operations in Binary, Octal, and Hexadecimal Systems Example 2.22 Perform the subtraction (61435 - 02798)10 using the nines-complement method. Solution: Minuend = 61435 stays unchanged -> 614351 Subtrahend = 02798 take nines-complement -> 97201 j + Make end carry an end around carry -> 158636 586361 End around carry -> 1 j + 58637 Therefore, (61435 - 02798)10 = (58637)10

Example 2.23 Perform the subtraction (02798 - 61435)10 using the nines-complement method. Solution: Minuend = 02798 stays unchanged -> 027981 Subtrahend = 61435 take nines-complement -> 38564 J + No end carry -> 41362 Since there is no end carry, we take the nines-complement of the sum 41362 and we place minus (-) sign in front of it resulting in -58637. Therefore, (02798 - 61435)10 = (-58637)10. Example 2.24 Perform the subtraction (1101100 - 1011011 )2 using the ones-complement method. Solution: Minuend = 1101100 stays unchanged -> 11011001 Subtrahend = 1011011 take ones-complement -> 0100100 j + Make end carry an end around carry -> 10010000 00100001 End around carry -> 1J + 0010001

2-12
FPGAs

Digital Circuit Analysis and Design with an Introduction to CPLDs and

Orchard Publications

Subtraction with Nines- and Ones-Complements Therefore, (1101100-1011011)2 = (0010001)2. Example 2.25 Perform the subtraction (1011011 - 1101100)2 using the ones-complement method. Solution: Minuend= 1011011 stays unchanged -> 10110111 Subtrahend = 1101100 take ones-complement -> 0010011 j + No end carry-> 1101110 Since there is no end carry, we take the ones-complement of the sum 1101110 and we place a minus (-) sign in front of it resulting in -0010001. Therefore, (1011011 - 1101100)2 = (-0010001 ) 2 . More advanced topics on arithmetic operations and number representations will be discussed in Chapters 3 andll.

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs

2-13

Orchard Publications

Chapter 2 Operations in Binary, Octal, and Hexadecimal Systems

2.7 Summary
In a binary addition, if the number of ones to be added in any column is odd, the sum digit for that column will be 1 , and if the number of ones to be added in any column is even, then the sum digit for that column will be zero. Also, a carry occurs whenever there are two or more ones to be added in any column. The addition of octal numbers is also very similar to decimal numbers addition except that when the sum of two or more octal numbers exceeds seven, a carry occurs just as a carry occurs when the sum of two or more decimal numbers exceeds nine. Table 2.1 offers a convenient method for octal addition and subtraction. The addition and subtraction of hexadecimal numbers is conveniently performed with the use of Table 2.2. The subtraction operation is simplified by the use of the complements of numbers. For each base-b system there are two useful types of complements, the bs-complement, and the (b-1)scomplement. Accordingly, for the base-10 system we have the tens-complements and the nines-complements, for the base-2 we have the twos-complements and ones-complements. The tens-complement of a number can be found by subtracting the least significant digit (lsd) of that number from 10 and then subtracting all other digits from 9 . The nines-complement of a number can be found by subtracting every digit (lsd) of that number from 9 . The twos-complement of a number can be found by leaving all the least significant zeros and the least significant one unchanged and then replacing all zeros with ones and all ones with zeros in all the other digits. The ones-complement of a number can be found by replacing all zeros with ones and all ones with zeros. The subtraction operation using tens-complement or twos-complements is performed as follows: 1.Take the tens-complement or twos-complement of the subtrahend and add it to the minuend which remains unchanged. 2.Check the result (sum), and a. if an end carry occurs, discard it. b. if an end carry does not occur, take the tens-complement or twos-complement of the result (sum) and place a minus ( - ) sign in front of it.

2-14
FPGAs

Digital Circuit Analysis and Design with an Introduction to CPLDs and Orchard Publications

Summary The subtraction operation using nines-complement or ones-complements is performed as follows: 1.Take the nines-complement or ones-complement of the subtrahend and add it to the minuend which remains unchanged. 2.Check the result (sum), and a. if an end carry occurs, add 1 - referred to as end around carry - to the lsd of the result (sum). b. if an end carry does not occur, take the nines-complement or ones-complement of the result (sum) and place a minus ( - ) sign in front of it.

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

2-15

Chapter 2 Operations in Binary, Octal, and Hexadecimal Systems

2.8 Exercises
1.Add 2.Add

the numbers (110010010)2 and (1011100)2 the numbers (110110)2 , (101001)2 , (100111)2 , (11010)2 , and (111101)2

3.Add the numbers (2735)8 and (6741)8 4.Subtract (145)8 from (416)8
5.Add the numbers (E743)16 and (F9C8)16 6.Subtract (8F9A)16 from (C5D7)16

7.Construct a table similar to Tables 2.1 and 2.2 for addition and subtraction of binary numbers. 8.Subtract (1011100)2 from (110010010)2 using the table constructed in Exercise 7. 9.Find the tens-complement of 67235 10.Find the tens-complement of 0.4268 11.Find the tens-complement of 752.0368 12.Find the nines-complement of 67235 13.Find the nines-complement of 275.6083 14.Find the twos-complement of 1111110000 15.Find the twos-complement of 0.010100 16.Find the twos-complement of 1000010.0001 17.Find the ones-complement of 1000001 18.Find the ones-complement of 0.0101 19.Find the ones-complement of 101001.0100 20.Perform the subtraction (43561 13820)10 using the tens-complement method. 21.Perform the subtraction (13820 43561)10 using the tens-complement method. 22.Perform the subtraction (1100100 1010011)2 using the twos-complement method. 23.Perform the subtraction (1010011 1100100)2 using the twos-complement method.

2-16
FPGAs

Digital Circuit Analysis and Design with an Introduction to CPLDs and

Orchard Publications

Exercises 24.Perform the subtraction (43561 13820)10 using the nines-complement method. 25.Perform the subtraction (13820 43561)10 using the nines-complement method. 26.Perform the subtraction (1100100 1010011)2 using the ones-complement method. 27.Perform the subtraction (1010011 1100100)2 using the ones-complement method. 28.A negative number is stored in a computing device in twos-complement form as 1100011.01011 What is the decimal value of this number?
29.The ones complement of a binary number N in a B-bit system is defined as (2B N)

1 . Prove

that (N) = N 30.The twos complement of a binary number N in a B-bit system is defined as 2B N . Using this definition prove that subtraction can be performed if we add the twos-complement of the subtrahend to the minuend.

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

2-17

Chapter 2 Operations in Binary, Octal, and Hexadecimal Systems

2.9 Solutions to End-of-Chapter Exercises


1. 1 110010010 1011100 111101110 Check: Carries +

Then,

(110010010)2 = (402)io (1011100)2 = (92)10 (111101110)2 = (402 + 92)io = (494)


10

2. 11 11111 lilil 110110 101001 100111 > + 11010 111101 Check:


11011101

Carries

(110110)2 = (54)(101001)2 = (41) 10 10 (100111)2 = (39)(11010)2 = (26)(111101)2 10 10 = (61)io (11001110)2 = (54 + 41 + 39 + 26 + 34) 10 = (221)

Then,

10

2-18

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

Solutions to End-of-Chapter Exercises 3. 11 Carnes 2735] 6741 J 11676 Check with MATLAB:
x=base2dec('2735',8); y=base2dec('6741',8); z=base2dec('11676',8); v=x+y; fprintf(' \n');... fprintf('x=%5.0f \t',x); fprintf('y=%5.0f \t',y); fprintf('v=%5.0f \t',v);... fprintf('z=%5.0f \t',z); fprintf(' \n')

x= 1501 4.

y= 3553

v= 5054

z= 5054 416] 145 J 251

Check with MATLAB:


x=base2dec('416',8); y=base2dec('145',8); z=base2dec('251',8); v=x-y;... fprintf(' \n');... fprintf('x=%3.0f \t',x); fprintf('y=%3.0f \t',y); fprintf('v=%3.0f \t',v);... fprintf('z=%3.0f \t',z); fprintf(' \n')

x=270 5.

y=101

v=169

z=169 E743] F9C8J 1E10B


) +

Check with MATLAB:


x=base2dec('E743',16); y=base2dec('F9C8',16); z=base2dec('1E10B',16); v=x+y;... fprintf(' \n');... fprintf('x=%6.0f \t',x); fprintf('y=%6.0f \t',y); fprintf('v=%6.0f \t',v);... fprintf('z=%6.0f \t',z); fprintf(' \n')

x= 59203 y= 63944 v=123147 z=123147

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

2-19

Chapter 2 Operations in Binary, Octal, and Hexadecimal Systems 6. C5D7 8F9A 363D Check with MATLAB:
x=base2dec('C5D7',16); y=base2dec('8F9A',16); z=base2dec('363D',16); v=x-y;... fprintf(' \n');... fprintf('x=%3.0f \t',x); fprintf('y=%3.0f \t',y); fprintf('v=%3.0f \t',v);... fprintf('z=%3.0f \t',z); fprintf(' \n')

x=50647 7.

y=36762

v=13885

z=13885

TABLE 2.3 Table for Addition and subtraction of binary numbers O 1

o r
10 When Table 2.3 above is used for addition, we first locate the least significant digit of the first number (augend) in the upper row of the table, and then we locate the least significant digit of the second number (addend) in the left most column of the table. The intersection of the augend with the addend gives the sum of these two numbers. We follow the same procedure for all other digits from right to left. When Table 2.3 above is used for subtraction, we first find the least significant digit of the subtrahend (the smaller number) in the first row of the table. Then, in the same column, we locate the least significant digit of the minuend (the larger number). If the least significant digit of the minuend is less than the least significant digit of the subtrahend, a borrow occurs and from table we choose the one whose least significant digit matches the least significant digit of the minuend. We find the difference by going across to the left most column. We follow the same procedure for all other digits from right to left. 8. 110010010 1011100 with MATLAB:
x=base2dec('110010010',2); y=base2dec('1011100',2); z=base2dec('100110110',2);... v=x-y;

100110110 Check

fprintf(' \n');...

2-20
FPGAs

Digital Circuit Analysis and Design with an Introduction to CPLDs and

Orchard Publications

Solutions to End-of-Chapter Exercises fprintf('x=%5.0f \t',x); fprintf('y=%5.0f \t',y); fprintf('v=%5.0f \t',v);... fprintf('z=%5.0f \t',z); fprintf(' \n')

x = 402
9.

y = 92

v = 310

z = 310

We first subtract 5 (lsd) from 10 and we get 5 . This is the lsd of the tens-complement. For the remainder part of the tens-complement, we subtract 3 , 2, 7, and 6 from 9 and we get 6, 7, 2, and 3 respectively. Therefore, the tens-complement of 67235 is 32765 . 10. We first subtract 8 (lsd) from 10 and all other digits from 9 . Therefore, the tens-complement of 0.4268 is 0.5732 . 11. We first subtract 8 (lsd) from 10 and all other digits from 9. Therefore, the tens-complement of 752.0368 is 247.9632. 12. We subtract every digit of the given number from 9 and we find that the nines-complement of 67235 is 32764 . We observe that this complement is one less than 32765 which we found in Exercise 9. 13. We subtract every digit of the given number from 9 and we find that the nines-complement of 275.6083 is 724.3916. 14. Starting from the right side of the given number we leave 10000 unchanged and then for the remaining digits, i.e, 11111 we replace the ones with zeros. Therefore, the twos-complement of 1111110000 is 0000010000 or simply 10000. 15. We leave the last three digits (100) unchanged and we replace the zeros with ones and the one with zero. Therefore, the twos-complement of 0.010100 is 0.101100 . The leading 0 to the left of the binary point that separates the integer and fractional parts remains unchanged. 16. We leave the lsd (last 1) unchanged and we replace the ones with zeros and the zeros with ones. Therefore, the twos-complement of 1000010.0001 is 0111101.1111 or 111101.1111. Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

2-21

Chapter 2 Operations in Binary, Octal, and Hexadecimal Systems 17. Replacing all ones with zeros and all zeros with ones we find that the ones-complement of 1000001 is 0111110 or 111110. 18. Replacing all ones with zeros and all zeros with ones we find that the ones-complement of 0.0101 is 0.1010. The leading 0 to the left of the binary point that separates the integer and fractional parts remains unchanged. 19. Replacing all ones with zeros and all zeros with ones we find that the ones-complement of 101001.0100 is 010110.1011 or 10110.1011. 20. Here, the first non-zero least significant digit of the subtrahend is 2 and it is subtracted from lO. Thus, Minuend = 43561 stays unchanged -> 43561 j Subtrahend = 13820 take tens-complement -> 86180 J + Discard end carry -> 129741 Therefore, (43561 - 13820)10 = (29741)10 21. Minuend = 13820 stays unchanged -> 138201 Subtrahend = 43561 take tens-complement -> 56439] + No end carry -> 70259 Since there is no end carry, we take the tens-complement of the sum 70259 and we place a minus (-) sign in front of it resulting in -29741. Therefore, (13820 - 43561)10 = (-29741 )10. 22. Minuend = 1100100 stays unchanged -> 1100100 j Subtrahend = 1010011 take twos-complement -> 0101101J + Discard end carry -> 10010001 Therefore, (1100100-1010011)2 = (10001)2 Check with MATLAB: x=base2dec('1100100',2); y=base2dec('1010011',2); z=base2dec('0010001',2);...

2-22

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

Solutions to End-of-Chapter Exercises v=x-y; fprintf(' \n');... fprintf('x=%5.0f \t',x); fprintf('y=%5.0f \t',y); fprintf('v=%5.0f \t',v);... fprintf('z=%5.0f \t',z); fprintf(' \n')

x = 100

y = 83

v = 17

z = 17

23.
Minuend= 1010011 stays unchanged -> 10100111 Subtrahend = 1100100 take twos-complement -^-0011100 [ No end carry-> 1101111 Since there is no end carry, we take the twos-complement of the sum 1101111 and we place a minus (-) sign in front of it resulting in -10001. Therefore, (1010011 - 1100100)2 = (-10001)2.

24.
Minuend = 43561 stays unchanged -> 435611 Subtrahend = 13820 take nines-complement -> 86179 j + Make end carry an end around carry -> 129740 29740] + End around carry -> 1 29741 Therefore, (43561 - 13820)10 = (29741)10

25.
Minuend = 13820 stays unchanged -> 13820 Subtrahend = 43561 take nines-complement -> 56438 No end carry -> 70258 Since there is no end carry, we take the nines-complement of the sum 70258 and we place a minus (-) sign in front of it resulting in -29741. Therefore, (13820-43561)10 = (-29741)10. +

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

2-23

Chapter 2 Operations in Binary, Octal, and Hexadecimal Systems 26.


Minuend = 1100100 stays unchanged -> 11001001 Subtrahend = 1010011 take ones-complement-> 0101100 j + Make end carry an end around carry -> 10010000 00100001 End around carry -> 1 [ 0010001 Therefore, (1100100-1010011)2 = (10001)2. 27. Minuend = 1010011 stays unchanged -> 10100111 Subtrahend = 1100100 take ones-complement -> 0011011 j + No end carry -> 1101110 Since there is no end carry, we take the ones-complement of the sum 1101110 and we place a minus (-) sign in front of it resulting in -0010001. Therefore, (1011011 - 1101100)2 = (-10001)2. 28. 1100011.01011 twos-complement-> 0011100.10101 and the unsigned decimal valu is (0011100.10101) 2 ->fl6 + 8 + 4 + - + - + ) = (28.65625)10 ^ 2 8 32^ JQ It is known that the given number is negative; therefore, its true decimal valu is -28.65625 . 29. Adding and subtracting (2B - 1) to -(-N) we get _(_N) = ( 2 B - 1 ) - [ ( 2 B - 1 ) - N ] = ( 2 B - 1 ) - ( 2 B - 1 ) + N = N 30. Suppose that X and Y are two positive numbers where X is the minuend and Y is the subtrahend. Then, X + (-Y) = X + (2B-Y) = 2B-(Y-X) (1)

2-24
FPGAs

Digital Circuit Analysis and Design with an Introduction to CPLDs and Orchard Publications

Solutions to End-of-Chapter Exercises but X + (2 - Y) = X + (-Y) or 2a = 0. Then, (1) above reduces to X + (-Y) = X + (2B-Y) = 2B-(Y-X) = O-(Y-X) = X-Y

Digital Circuit Analysis and Design with an Introduction to CPLDs and FPGAs Orchard Publications

2-25

Das könnte Ihnen auch gefallen