You are on page 1of 7

Unit -2

Lecture 9
2s Complement Addition/Subtraction

 Algorithm for addition, A + B:


1. Perform binary addition on the two numbers.
2. Ignore the carry out of the MSB (most significant bit).
3. Check for overflow: Overflow occurs if the ‘carry in’ and ‘carry out’ of the
MSB are different, or if result is opposite sign of A and B.
 Algorithm for subtraction, A – B:
A – B = A + (–B)
1. Take 2s complement of B by inverting all the bits and adding 1.
2. Add the 2s complement of B to A.
• If carry
– Discard it
– Answer is positive
• Else
– Answer is negative
– So, answer is in 2’s complement form
2’s Complement Addition and Subtraction
Hardware Flowchart
Overflow
• Overflow in unsigned addition – result occupies more
number of bits.
• Overflow in signed-magnitude / 2’s complement addition
• result occupies more number of bits
• addition of two positive number resulting negative number
• sum of two negative numbers resulting in positive number.
• There will no overflow during unsigned subtraction /
signed – magnitude subtraction.
Overflow / Underflow Problem
• Overflow – when the addition of two binary numbers yields a result
that is greater than the maximum possible value
• Underflow – when the addition/subtraction of two binary numbers
yields a result that is less than the minimum possible value

Overflow Underflow
• Assume 4-bit restriction and 2’s • Assume 4-bit restriction and 2’s
complement complement
• Maximum possible value: 24-1 – 1 = 7 • Minimum possible value: -(24-1) = -8

610 + 310 = 910 -510 + -510 = -1010

01102 610 10112 -510


+00112 +310 +10112 +-510
10012 -710  not good! 01102 610  not good!
Overflow of Signed Numbers

carry carry and


generated, overflow
but no
overflow

no carry no carry
and no and
overflow overflow

Cin Cout = 1 => Overflow


Problem
• Perform the arithmetic operations below with
binary numbers and with negative numbers in
signed 2’s complement representation. Use
seven bits to accommodate each number
together with its sign. In each case, determine
if there is an overflow by checking the carries
into and out of the sign bit position
(+35) + (+40)
(-35) + (-40)
(-35) – (+40)

You might also like