Search code examples
binaryoverflowadditionsignedtwos-complement

Adding 8 bit numbers using signed 2's complement


Either there is some confusion with what is written below or my textbook is wrong. I was looking at examples in my textbook for addition of 8 bit signed binary digits using 2's complement and came across these examples. We are required to find if any overflow occurs


Example 1]

Adding +75 and -58

+75 = 01001011 ... (a)
+58 = 00111010
-58 = 11000110 ... (b) [took 2's complement of +58]

now adding (a) and (b) we get

     01001011
+   11000110
  1]00010001

It was written in textbook that overflow occurs with an arrow pointing to that extra 1 separated with a square bracket. This example is ok and from here I understood that if there is and extra 1 then we have a overflow.

(Question 1: Am i correct with what i understood ?)


Example 2: This example confused me

Add 53 and (-13)

53 = 00110101
-(13) = 11110011

now adding both we get

00110101 + 11110011 = 1]00101000

And then they wrote: Carry in and carry out for signed bit is 1. So no overflow. Discarding the carry bit and rest is the positive required result

(The main Question: Even though there was this overflow digit(extra 1) why did they say its not overflow. And what are these carry in and carry out for signed bit written in above sentence.)


I did a lot of Google search but couldn't find a good reasonable solution to this line they talked about, or may be it was in front of my eyes but i didn't understand. Somebody please clarify. Most examples I saw(on stack-overflow and other sites) were for 4 bits that confused a bit more. Somebody please help me clarify, Thanks.


Solution

  • Overflow occurs only when correct answer cannot be interpreted using given number of bits.An extra bit is required to interpret the answer right.Consider the following example of byte numbers addition:

    +70 in binary 01000110

    +80 in binary 01010000

    On addition :10010110

    1 in the MSB(most significant bit) indicates that answer is negative which is wrong.However if we include an extra 9th bit as a sign bit(=0) we have the answer as 010010110 = 150.The value of this extra sign bit is equal to the carry as a result of addition of bits in MSB(which in this case = 0).

    Reference : Computer System Architecture by M.Morris Mano.