BINARY ADDITION AND SUBTRACTION WITH OVERFLOW RULE


What is binary numbers?

Binary means two numbers i.e 0 or 1.

What is binary addition and subtraction?

Addition and subtraction are arithmetic operators.

Binary addition means adding between two binary numbers.

Binary subtraction means subtracting between two binary numbers.

 

Overflow rule:

In general term, overflow means , a thing more than capacity and it is wastage.

In computer organization,Overflow occurs when the resulting value of an operation performed on valid representations of numbers is out of the range of valid values. That is, the resulting value is greater than max or less than min.

How overflow occurs depends:

  • the operation being performed,
  • the representation system used to represent the numbers,
  • and the number of bits used

 

lets take an example,

If you are representing numbers using 4 bits as unsigned binary, the minimum value is 0 (i.e., 00002, while the maximum value is 15 (11112).

Any operation that results in a number larger than 15 or smaller than 0 has overflowed.

Suppose i want to add 15 + 15 (1111 + 1111) , we can represent 15 in 4 bits but after addition the result will be 30. That, is not possible in 4 bits. so this is overflow.

 

Remember: −2n−1 ≤ Two’s Complement ≤ 2n−1 − 1

−8 ≤ x[4] ≤ +7

−128 ≤ x[8] ≤ +127

−32768 ≤ x[16] ≤ +32767

−2147483648 ≤ x[32] ≤ +2147483647

Two’s complement addition:

Add the values and discard any carry-out bit.

Examples: using 8-bit two’s complement numbers.

 

  1. Add −8 to +3
(+3)   0000 0011
+(−8)   1111 1000
-----------------
 (−5)   1111 1011  no overflow

Add −5 to −2
 (−2)   1111 1110
+(−5)   1111 1011
-----------------
 (−7) 1 1111 1001 overflow occur


Now, the shortcut method to know that overflow will occur or not?

firstly, see some example:


1011 + 10010 = 11101:

            1    
  0 0 0 0 1 0 1 1
+ 0 0 0 1 0 0 1 0
  0 0 0 1 1 1 0 1
No overflow. Sum is correct.
1010110 + 110100 = 10001010:

  1 1 1   1      
  0 1 0 1 0 1 1 0
+ 0 0 1 1 0 1 0 0
  1 0 0 0 1 0 1 0
No overflow. Sum is correct.
11001011 + 1011010 = 100100101:

1 1   1 1   1    
  1 1 0 0 1 0 1 1
+ 0 1 0 1 1 0 1 0
  0 0 1 0 0 1 0 1
Overflow. The carry-out is discarded, and the sum is not correct
1010001 + 11001 = 1101010:

      1       1  
  0 1 0 1 0 0 0 1
+ 0 0 0 1 1 0 0 1
  0 1 1 0 1 0 1 0
No overflow. Sum is correct.
110001 + 11100100 = 100010101:

1 1 1            
  0 0 1 1 0 0 0 1
+ 1 1 1 0 0 1 0 0
  0 0 0 1 0 1 0 1
Overflow. The carry-out is discarded, and the sum is not correct
10011011 + 1001010 = 11100101:

      1 1   1    
  1 0 0 1 1 0 1 1
+ 0 1 0 0 1 0 1 0
  1 1 1 0 0 1 0 1
No overflow. Sum is correct.
 

 

GOLDEN RULE OF ADDITION

If 2 Two’s Complement numbers are added with each other, and they both have the same sign (both positive or both negative), then overflow occurs if and only if the result has the opposite sign. Overflow never occurs when adding operands with different signs.

Overflow occurs if

  • (+A) + (+B) = −C
  • (−A) + (−B) = +C

 

Example: Using 4-bit Two’s Complement numbers (−8 ≤ x ≤ +7)

 (−7)   1001
+(−6)   1010
------------
(−13) 1 0011 = 3 : Overflow occur (largest −ve number is −8)



BINARY SUBTRACTION

Subtrahend: what is being subtracted
Minuhend: what it is being subtracted from

Example: 400 - 200 = 200

200 is the subtrahend, 400 is the minuhend, 200 is the result

 

If 2 Two’s Complement numbers are subtracted, and their signs are different, then overflow occurs if and only if the result has the same sign as the subtrahend.

Overflow occurs if

  • (+A) − (−B) = −C
  • (−A) − (+B) = +C

Example: Using 4-bit Two’s Complement numbers (−8 ≤ x ≤ +7)

Subtract −6 from +7

     (+7) 0111               0111
    −(−6) 1010 -> Negate -> +0110
    ----------              -----
      13                     1101 = −8 + 5 = −3 : Overflow 


Numbers can be added or subtracted by moving round the number circle

  • Clockwise for addition
  • Anti-Clockwise for subtraction (addition of a negative number)

 

WHEEL OF ADDITION AND SUBTRACTION OF 4 BITS NUMBER:

unsignedwheel

                                                 fig a wheel of addition and subtraction

In the above fig a, you can see when we will add two numbers 1 + 2 then it will go to the right side and no overflow occurs.

if the numbers are large or you can say that out of range then overflow will occur i.e 7 + 7 =14

In this case, range is out of bound it will go to the negative value .

 

NUMBER                 IN BINARY                        

0                                   0000                                    

1                                   0001

2                                   0010

3                                   0011

4                                   0100

5                                   0101

6                                   0110

7                                   0111

8                                   1000

9                                   1001

10                                 1010

11                                 1011

12                                 1100

13                                 1101

14                                 1110

15                                 1111

In the above table, after 7(0111) then next value is the reverse of it i.e (1000)

6(0110) is the reverse of 9(1001).

this is the logic which is not mentioned in any book.