Courses In Electrical Engineering
Volume II DIGITAL ELECTRONICS CHAPTER FIVE : DIGITAL ARITHMETIC
By J-P. NGOUNE DIPET I (Electrotechnics), DIPET II (Electrotechnics) DEA (Electrical Engineering) Teacher in the Electrical Department, GTHS KUMBO, Cameroon.
Digital Electronics_Jean-Paul NGOUNE
Chapter Five
DIGITAL ARITHMETIC
5.0 Specific objectives: At the end of this chapter, the student will be able to perform arithmetical operations such as addition, subtraction, and multiplication using binary numbers
5.1 Introduction: Many arithmetical operations are carried out in digital systems like computers and calculators. The most common of these operations are addition, subtraction and multiplication. The aim of this chapter is to understand the principle used by digital systems to perform those operations. 5.2 Binary addition: The addition of two binary numbers is similar to that of two decimal numbers. Let us consider the following case: 354 +663 10 1 7 This operation is performed using the following steps: We begin by adding the two less significant digits of the two decimal numbers: 3 + 4 =7. There is no carry out. Then we proceed by adding the two digits situated directly at the left: 5 + 6 = 11. We write 1 and the carry out is 1. We add the two next digits: 3 + 6 = 9; the carry out is added: 9 + 1 = 10. So the result of the addition is 1017. For binary number, the principle is the same. However, only four cases can be met while adding binary numbers: 0+0=0 1+0=1
Digital Electronics_Jean-Paul NGOUNE
1 + 1 = 0 + a carry out of 1 1 + 1 + 1 = 1 + a carry out of 1.
Example 5.1: Let us add the following binary numbers: A = 1001 (910), B = 1111 (1510). 1001 +1111 11000
We begin by adding the two LSB (Least Significant Bit): 1 + 1 = 0 + carry out of 1. Then we add that carry to the two bits situated directly at the left: 0 + 1 + 1(Carry) = 0 + carry out of 1. The same operation is performed for the next rank. Then for the most significant bits, we have:
1 +1 + 1(Carry from the previous rank) = 11. Finally, the result of the operation gives us 11000 (2410).
Exercise 5.1: For each of the following cases, add the binary numbers A and B. a) A = 11101; B = 1001. b) A = 101111; B = 11111. c) A = 11101; B = 11111. 5.3 Signed numbers: In order to differentiate positive numbers to negative numbers, a specific bit can be added in front of the binary number. That bit is called bit of sign. The bit of sign is 0 for positive numbers and 1 for negative numbers. Example 5.2:
+9 = 01001 -24 = 111000
Digital Electronics_Jean-Paul NGOUNE
For negative binary numbers, there are two other types of notation: The ones complement notation; The twos complement notation.
5.3.1 The ones complement notation: The ones complement notation of a binary number is simply obtained by complementing each bit of the number. Let us write for example the ones complement of the following binary number: 10010110 10010110 01101001 Remark 5.1: For negative binary numbers, we should not forget the bit of sign: 11101 10010 Exact notation Ones complement notation. Exact notation Ones complement notation
Notice that the bit of sign is not complemented. Exercise 5.2: Give the ones complement of the following binary numbers. a) 101101; b) 1101101 (signed number); c) 011101011 (signed number).
5.3.2 The twos complement notation The twos complement notation of a binary number is obtained by adding 1 to the ones complement notation of that number. 110110 001001 + 1 Twos complement notation Exact notation Ones complement notation
001010
For signed number, remember that the bit of sign remain unchanged. Exercise 5.3: Give the twos complement of the following binary numbers. b) 101101; b) 1101101 (signed number); c) 011101011 (signed number).
Digital Electronics_Jean-Paul NGOUNE
We can recapitulate all what we have studied concerning ones and twos complementation in the following table: Decimal +24 -24 Exact notation 011000 111000 Ones complement 011000 100111 Twos complement 011000 101000
Notice that for positive numbers, exact notation does not differ from ones complement and twos complement notation. 5.3.3 Conversion from ones complement and twos complement notation to exact notation: To convert from the ones complement notation to the exact notation, each bit of the ones complement notation should just be complemented back. 111000 100111 111000 Exact notation. Ones complement notation. Exact notation.
Notice that the bit of sign does not change. To convert from twos complement notation to the exact notation, the twos complemented number should just be twos complemented back. 1001 0110 + 1 Twos complement notation Exact notation
0111 1000 + 1
1001
Exact notation
5.4 Addition of two signed numbers: Depending on the sign of the two numbers to be added, many cases can be studied. Case 1: Two positive numbers: Let us add +4 to +9. +9 = 01001 +4 = 00100
Digital Electronics_Jean-Paul NGOUNE
+9 +4 +13
01001 +00100 01101 The two numbers to be added should have the same number of bit and they
should also be written in twos complement notation. Exercise 5.4: In each of the following cases add numbers A and B after having converted them in binary: a) A = +10; B = +12; b) A = +3; B = +20; c) A = +45, B = 19.
Case 2: Positive number and negative number (less than the positive number). Let us add +9 and -4. Decimal +9 -4 Exact notation 01001 10100 2s complement 01001 + 11100 100101
The result gives us 100101: The first bit 1 is not taken in consideration. The second bit 0 is the bit of sign, so the result of the operation is 00101 = 510. Case 3: Positive number and negative number greater (greater than the positive number) The result of this operation should give a negative number written in twos complement notation. Therefore, that result should later on be converted from twos complement notation to exact notation. Decimal -9 +4 Exact notation 11001 00100 2s complement 10111 + 00100 11011 Result in 2s complement notation
Digital Electronics_Jean-Paul NGOUNE
Let us convert now the result from twos complement to exact notation 11011 10100 + 1 Final result The final result is 10101= -510. Exercise 5.5: Solve the following operations in binary: a) 810 - 510 b) 1210 - 610 c) 610 - 1210 d) 510 - 1210 Case 4: Two negative numbers Let us add -9 and -4: Decimal -9 -4 Exact notation 11001 10100 2s complement 10111 + 11100 110011 Result in 2s complement notation
10101
The first bit of the result in twos complement is not taken in consideration. Let us convert the result from twos complement notation to exact notation: 10011 11100 + 1 Final result
11101
The final result is 111012= - 1310.
Digital Electronics_Jean-Paul NGOUNE
Case 5: Two opposite numbers Let us add -9 and +9 Decimal -9 +9 Exact notation 11001 01001 2s complement 10111 + 01001 100000 Result in 2s complement notation
The first bit of the result in twos complement is not to be taken in consideration. By converting the result from twos complement notation to the exact notation, we stiil obtain 0. 00000 01111 + 1 Final result
10000
The result in exact notation gives us 100002 = -010. Remark 5.2: Subtraction of binary numbers The subtraction of two binary numbers can easily be transform into addition, for example: +9 (+4) = +9 + (-4) +9 (-4) = +9 + (+4) Remark 5.3: Overtaking Let us add +9 and +8 Decimal +9 +8 Exact notation 01001 01000 2s complement 01001 + 01000 10001=1710 Result in 2s complement notation
The first bit of the result should be normally considered as the bit of sign. But if we do so, it means that there is an error (because the result will be -110 Iinstead of 1710). That error is called overtaking error because we need one more bit (over bit) to well represent the result of the operation which is 0100012 = +1710.
Digital Electronics_Jean-Paul NGOUNE
In digital systems, there are special circuits intended to detect overtaking errors during calculations. 5.5 Multiplication of binary numbers: The multiplication of two binary numbers is similar to that of two decimal numbers. Let us multiply 910 (10012) and 310(00112). Decimal +9 +3 Exact notation 01001 00011 2s complement 01001 x 00011 01001 01001 011011
The final result gives us 0110112 = 2710. The bits of first number (9) have just been multiplied by each of those of the second number (3), beginning from the right to the left. It should also be noticed that, while passing from one line to the next, we should shift from one position to the left. Let us multiply -5 and +4: Decimal -5 4 Exact notation 1011 0100 2s complement 1011 x 0100 0000 0000 1011 101100 Result in 2s complement notation
Let us convert the result from 2s complement notation to the exact notation: 101100 110011 +1 110100 Final result
The final result gives us 1101002 = -2010.
Digital Electronics_Jean-Paul NGOUNE
Exercise 5.6: Calculate the following: a) -6 x -4 b) -3 x +5 c) -5 x +6
5.6 Addition of DCB numbers: As we have already seen in the first chapter, to convert a number from decimal system of numeration to DCB code, each digit of the decimal number should be replaced by its binary equivalent in four bits. Valid DCB codes go from 0000 (010) to 1001(910). The addition of two DCB numbers is almost similar to that of binary numbers. However, when the result of the operation gives us numbers that do not belong to DCB range of valid codes, a correction should be done on the found result by adding 1102 to it. 4510 3310 0100 0101 + 0011 0011 0111 1000 7 8
The final result gives us 0111 1000(DCB) = 7810 610 710 0110 + 0111 1101 13 (invalid DCB code)
The result gives us 1101 = 1310 (in four bits) which is an invalid DCB code. To correct this result, 110 should be added to it. 1101 + 110
0001 0011 1 3
The final result gives us 0001 0011(DCB) = 1310
Digital Electronics_Jean-Paul NGOUNE
10
Exercise 5.7: Add the following number after converting them in DCB: a) 5410 + 2310 b) 4910 + 25 10 c) 5510 + 6910 5.7 Addition and subtraction of hexadecimal numbers: 58 +24 7C16 In fact, 8 + 4 = 12 (C16) 58 +4B A316 In fact, 8 + B = 1910 (1316). We write 3 and the carry out (which is 1) is added to the rank directly at the left. Addition:
Let us add the following hexadecimal numbers:
Exercise 5.8: Add the following: a) 2A + 56 b) 3AF + 5EB c) F8C + 7B 1A - CF The first step of the solution is to determine the twos complement of CF. Subtraction
Let us solve the following:
Digital Electronics_Jean-Paul NGOUNE
11
CF
1100 1111 0011 0000 + 1
0011 0001 3 1
Then the operation can be solved just as a simple addition: 1A +31 4B
5.8 Conclusion The present chapter has permitted us to know how to perform basic arithmetical operations such as addition, subtraction and multiplication involving binary numbers. Operations with hexadecimal and DCB numbers have also been introduced. The next chapter is focused on the study of basic combinatory logic circuits. Those circuits are elements used in the conception of complex logic systems.
REVIEW QUESTIONS
1. Determine the ones complement of the following binary numbers: a) 1100101.11 b) 100101011 c) 0110110.11 (signed number) d) 1110111.1101 (Signed numbers) 2. Determine the twos complement of the binary numbers given in the exercise above (exercise 1). 3. Perform the following operation after converting each number involved to binary: a) +9 + (+4) b) -9 + (-5)
Digital Electronics_Jean-Paul NGOUNE
12
c) +29 + (+7) d) +3 + (-21) e) +14 - (-45) f) 22 (+12) g) +12 x (+4) h) 5 x ( -4) 4. Add the following DCB number and correct the result if necessary: a) 0110 1001 + 1000 0101 b) 1001 0110 + 0111 0001 c) 0100 0011 + 0101 0100 5. Perform the following operations involving hexadecimal numbers: a) 4EB + 7C b) 54 +69 c) 7FF-23 d) 6FC+5BC
References: 1. Digital systems, principles and applications, Ronald J.Tocci, 3rd edition, Prentice-Hall inc., Englewood Cliffs, New Jersey , USA,1985. 2. Lessons In Electric Circuits Volume IV Digital, Tony R. Kuphaldt, Fourth Edition, 2007, www.allaboutcircuits.com . www.ibiblio.org/obp/electricCircuits. 3. Cours de systmes logiques, Notes de cours, Premire anne du gnie lectrique, ENSET de Douala, J.C Tsokezo, 2004-2005.
Digital Electronics_Jean-Paul NGOUNE
13