Friday, February 3, 2012

Ones complement arithmetic


consider the arithmetic x-y and x+y. For computing these two equations in the normal way we need two different circuits because they do different two operations. The use of ones complement comes here as x-y can be also represented as x+ 1's complement of y. This eliminates the use of two different circuits for addition and subtraction.

In our examples below we use 4 bit numbers and assumes that the um should be less than or equal to 15. If it exceeds 15 we will get an incorrect answer. 

+3=
0,
0
0
1
1
+7=
0,
0
1
1
1
+10
0,
1
0
1
0


+8=
0,
1
0
0
0
+9=
0,
1
0
0
1

1,
0
0
0
1
Not correct as the sum exceeds 15

Addition rules

  1. If an over flow is produced beyond the sign bit while adding two signed numbers, then the over flow bit is removed and added to the result. The examples below explains it.


    2. If a positive number is added to a negative number and does not result in a over flow , then the result is negative and is in ones complement form. An example is given below.

    -5 1, 1 0 1 0
    +3 0, 0 0 1 1
    -2 1, 1 1 0 1   

    3. If two negative numbers are added there will be a over flow. This over flow bit is added to the result. The sign will be that of the final answer. The magnitude of the sum should be less than 15 in this case as we use only 4 bit operands. Some examples are shown below.  







No comments:

Post a Comment