Perform twos complement arithmetic for the followings. 6. -17 + (-31) 7. 51 – 78 8. -19 + 35 9. -71 + (-31) 10. -120 + (-127)
The Correct Answer and Explanation is:
Problem 6: -17 + (-31)
Binary representation (8-bit):
-17 → 11101111
-31 → 11100001
Addition:
arduinoCopyEdit 11101111
+ 11100001
-----------
1 11010000 (9 bits: discard overflow bit)
Result: 11010000 → Two's complement of this gives 72 → Answer is -72
Problem 7: 51 – 78
This becomes 51 + (-78)
51 → 00110011
-78 → 10110010
Addition:
markdownCopyEdit 00110011
+ 10110010
-----------
11100101 → Two's complement of this gives 27 → Answer is -27
Problem 8: -19 + 35
-19 → 11101101
35 → 00100011
Addition:
markdownCopyEdit 11101101
+ 00100011
-----------
00010000 → Result is positive → Decimal: 16
Problem 9: -71 + (-31)
-71 → 10111001
-31 → 11100001
Addition:
markdownCopyEdit 10111001
+ 11100001
-----------
1 10011010 (discard overflow)
Result: 10011010 → Two's complement of this is 102 → Answer is -102
Problem 10: -120 + (-127)
-120 → 10001000
-127 → 10000001
Addition:
pgsqlCopyEdit 10001000
+ 10000001
-----------
1 00001001 (discard overflow)
Result: 00001001 → 9 → **Incorrect!** This is overflow!
Correct result exceeds 8-bit signed range (−128 to 127) → **Overflow occurs**
Textbook-Style Explanation
Two’s complement arithmetic is the standard method for performing binary arithmetic with signed integers in digital systems. In two’s complement representation, positive numbers are represented in standard binary form, while negative numbers are represented by inverting all bits of the number’s absolute binary value and adding one. For 8-bit systems, the representable range is from -128 to +127.
To add two signed numbers using two’s complement, convert both numbers into their 8-bit binary representations. For negative numbers, compute their two’s complement form. This involves inverting the bits of the absolute binary value and adding 1. Then, simply add the binary numbers together. If the result produces a 9-bit number, the leftmost carry bit (the overflow bit) is discarded.
The result is interpreted as follows: if the leftmost bit (most significant bit) is 0, the result is positive and can be read directly. If the leftmost bit is 1, the result is negative. To find the actual value, take the two’s complement of the result and add a negative sign.
Overflow occurs when the result of an addition falls outside the valid range of the signed integer format (for 8 bits, this is −128 to +127). When adding two negative numbers results in a positive binary output (or vice versa), overflow is indicated, and the result is unreliable.
Two’s complement arithmetic allows subtraction to be performed as addition of a negative, such as computing 51 − 78 by adding 51 + (−78). This simplifies circuit design and enables consistent processing of both positive and negative integers.
Understanding two’s complement is essential for low-level programming, computer architecture, and digital systems design.
