Aditya Pednekar
Aditya Pednekar

Reputation: 462

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.

Upvotes: 1

Views: 28281

Answers (4)

Uruk-hai
Uruk-hai

Reputation: 659

simplest rule while calculating 8 bit number.

Carry-Bit  |    Sign-Bit     
-----------------------------------------------------
   0       |      0       --> No Underflow or Overflow
   1       |      1       --> No Underflow or Overflow
   0       |      1       --> OVerflow
   1       |      0       --> Underflow

Upvotes: 0

Basant
Basant

Reputation: 21

I will try to resolve your doubt with the help of examples, where we will ADD two numbers using signed 2's complement method.

But before that let me tell you the condition when Overflow occur.

Basically, overflow occur when carry into the sign bit is not equal to the carry out of the sign bit.


Example Number 1:

Decimal  Carry out   Sign bit    2’s Complement

 -65         -          1         011 1111

 -15         -          1         111 0001
---------------------------------------------
 -80         1          1         011 0000

1's complement of 0110000 = 1001111
Adding Overflow digit 1 to 1001111 we will get our answer as 1010000.
With signed bit we will get - 1 1010000 which is equal to -80

Carry into the Sign bit = 1

Carry out of the Sign bit = 1

Therefore, No OVERFLOW


Example Number 2:

Decimal  Carry out   Sign bit    2’s Complement

 -65         -          1         011 1111

 -75         -          1         011 0101
--------------------------------------------
-140         1          0         111 0100

Carry into the Sign bit = 0

Carry out of the Sign bit = 1

Therefore, OVERFLOW

I hope, that this must have cleared your doubts about Overflow and signed 2's complement Binary Addition technique.

Upvotes: 2

Sourav Kumar
Sourav Kumar

Reputation: 1

Add the following using 8 bit signed 2's complement representation:

  • 25 and -40

  • 75 and 80

Upvotes: -1

Sumeet
Sumeet

Reputation: 8292

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.

Upvotes: 4

Related Questions