In: Computer Science
What is the 8-bit sum of the following 2’s complement numbers: 11101100+00001101? Show your work.
Finding sum of numbers in 2's complement format is similar to finding the sum of unsigned numbers.What we need to take care while finding the sum is whaether there is an overflow or not.We need to check on overflow .In this case we have 2 8 bit numbers and that is too be stored on a 8-bit register as well.If there is an overflow then the result is invalid.
Here are few of my examples to illustate how addition takes place in 2's complement system taking care of the overflow .
One thing is to be noted that an overflow in 2's complement form doesnt always mean that the result is invalid.Following are the times when an overflow occurs:--
The rules for detecting overflow in a two's complement sum are simple:
It is important to note the overflow and the carry in and carry out.If both carry in and carry out are not equal,then there is an overflow and the result is invalid result.
Few examples on binary addition of numbers :--
-39 + 92 = 53:
1 | 1 | 1 | 1 | |||||
1 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | |
+ | 0 | 1 | 0 | 1 | 1 | 1 | 0 | 0 |
0 | 0 | 1 | 1 | 0 | 1 | 0 | 1 |
Carryout without overflow. Sum is correct.
-19 + -7 = -26:
1 | 1 | 1 | 1 | 1 | 1 | |||
1 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | |
+ | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
1 | 1 | 1 | 0 | 0 | 1 | 1 | 0 |
Carryout without overflow. Sum is correct.
43 + 46 = 89:
No overflow nor carryout. |
||||||||||||||||||||||||||||||||||||||
• 104 + 45 = 149:
Overflow, no carryout. Sum is not correct. |
. |
127 + 1 = 128:
1 | 1 | 1 | 1 | 1 | 1 | 1 | ||
0 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | |
+ | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 |
1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Overflow, no carryout. Sum is not correct.
HERE IS THE ANSWER TO PROBLEM ASKED THE ABOVE EXAMPLES WILL HELP TO UNDERSTAND THIS BETTER:--
-20 + 13 = -7
1 | 1 | |||||||
1 | 1 | 1 | 0 | 1 | 1 | 0 | 0 | |
+ | 0 | 0 | 0 | 0 | 1 | 1 | 0 | 1 |
1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 |
" No overflow nor carryout. SUM IS =-7 AND IS CORRECT ."