Showing posts with label binary subtraction. Show all posts
Showing posts with label binary subtraction. Show all posts

Friday, February 3, 2012

2's complement arithmetic


Addition of two positive number: The addition of positive number follows the same rules that of the binary addition.

The magnitude of the sum should be in range(ie it should not go out of range of the system). If the sum goes out of range the sign bit will become 1.

Eg
+8   0,1000
+10 0,1010
---------
1,0010 (This answer is incorrect because in here we consider a 4bit operands)

2's complement subtraction: It is the addition of minuend to the 2's complement of the subtrahend. The sign bits of the two numbers are considered as a part of the number and is used in the addition.

Eg +5 0,0101
      -3 1,1101 (2's complement of 3)
         ---------
   +2 10,0010          (the one is ignored) 

The over flow produced in the addition is ignored. The bit in the sign bits position will be the correct sign bit after addition. If the result is negative it will be in 2's complement form.

Eg -5 1,1011
    +3 0,0011
       --------
    -2 1,1110

Addition of two negative numbers in 2's complement form: Here also the over flow bit is discarded. The sign bit is correct if the result is in the allowed range(for 4 bit operand the range is <=15). The sign bit will become 1 indicating error if the answer goes out of range.

Eg -5 1,1011
     -3 1,1101
        ---------
    -8 11,1000


Eg -8 1,1000
     -9 1,0111
      ----------
       10,1111 (not correct as the result goes out of range)


Friday, January 27, 2012

Binary subtraction


Binary subtraction

Before explaining subtraction lets see how negative numbers are represented in binary. To denote the sign of a binary number a extra bit is used in the left end of the number. By convention zero is used to represent + sign and a one is used to represent -sign.

+5 = 0,101
-7 = 1,111

Subtraction is the process of adding a negative number to a positive number. If a number having a positive sign is added to a number with a number y having a negative sign ,it is equivalent to subtracting y from x.

Consider the example below
101-011

Borrow
1
0

Minuend
1
0
1
Subtrahend
0
1
1
Difference
0
1
0


Borrow
0
Minuend
0
Subtrahend
0
Difference
0

Borrow
1
Minuend
0
Subtrahend
1
Difference
1

From the above examples we can construct a half subtracter table and full subtracter table.



Half subtracter

a
b                                       Difference             Borrow
0
0
0
0
0
1
1
1
1
0
1
0
1
1
0
0

Full subtracter

A(Minuend)
B(Subtrahend)
Borrow
Difference
Borrow to next position
0
0
0
0
0
0
0
1
1
1
0
1
0
1
1
0
1
1
0
1
1
0
0
1
0
1
0
1
0
0
1
1
0
0
0
1
1
1
1
1