Showing posts with label ones compliment. Show all posts
Showing posts with label ones compliment. Show all posts

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.  







Tuesday, January 31, 2012

Compliment representation of numbers

In sign magnitude system the sign of a binary number is denoted by a extra bit in-front of the number.

For example +5 is denoted by 0,101.

0 : show that the number is positive
1: show that the number is negative

Ones compliment

In ones compliment system the representation of positive number is the same as that of sign magnitude system. But the representation of negative number is different.

For example -5 is represented in ones compliment as 1,010. This is obtained by replacing all the 1s by 0 and zero by 1 in the binary representation of +5 which is 0,101.

The process of replacing a 0 by 1 and 1 by 0 is called bits complimenting.

In general a n bit number x's (with out sign bit) ones compliment is given by (2^n-1-x).

Twos compliment

The twos compliment is obtained by adding 1 to the ones compliment of a number.

Example:

+5=0,101
-5=1,010 (1s compliment)

now twos compliment of -5 is 1,010 + 0001 = 1,011

In general for an n bit number twos compliment is given by 1,(2^n-x). Another method to to find the twos compliment of a binary number is to scan the number from left to right and compliment all the bits appearing after the first one. An example I given below.

0,1110 → 1,0010