Given Question:
Assume 151 and 214 are signed 8-bit decimal integers stored in two’s complement format. Calculate 151+214, the result should be written in decimal. Check for overflow. Hint: overflow occurs when the result of adding two positive numbers is negative.
Instructor's Solution:
Step 1:
Write the two numbers in binary:
214 = 11010110
151 = 10010111
Step 2:
Rewrite using two's complement representation:
214 = 11010110 = 00101010
151 = 10010111 = 01101001
Step 3:
Convert results of two’s complement to decimal:
214 = 11010110 = 00101010 = -105
151 = 10010111 = 01101001 = -42
Step 4:
Add: 100101010+01101001 = 10010011
Step 5:
Convert results to decimal: 10010011 = -147
Conclusion: As can be noted, there is overflow
My questions are:
In step 1: Why are the MSBs of the results of converting 214 and 151 to binary equal to 1 (negative) when 214 and 151 are both positive? Aren’t their values in binary equal to 011010110 and 010010111 respectively?
In step 3: After converting the results of two’s complement of both numbers to decimal, why is the sign negative if the MSB is 0 (positive)?