Categories

Subtraction using (r-1)’s compliment

(r – 1) ’s compliment:   (M – N) r

This is similar to r’s compliment. There is a difference while dealing with the final carry we get

If we have both M & N positives, then

The Procedure for doing subtraction using (r – 1) ’s compliment is as follow:

1. Take (r – 1) ’s compliment of subtrahend N
2. Add it to minuend M
3. If we get a carry, add 1 to the result otherwise take (r – 1)’s compliment of the result and place a –ve sign in front of it.

If we have negative M & positive N, then i.e. – m – n where m & n are magnitudes of M&N

The Procedure for doing subtraction using (r – 1) ’s compliment is as follow:

1. Take (r – 1) ’s compliment of subtrahend N
2. Add it to minuend M

If we get a carry, add 1 to the result and also take (r – 1’s compliment and place a –ve sign in front of it otherwise if there is no carry then do nothing

Eg. 10101002 – 10001002

1’s compliment of 1000100 is 0111011 and then adds to 1010100

Eg. 10001002 – 10101002

1’s compliment of 1010100 is 0101011 and it is added to 1000100

As we don’t have carry so we take 1’s compliment of the result and put the –ve sign in front

We don’t have to worry about whether M is larger or N is larger, carry which we get takes care of this thing. So one has to just follow the procedure and we’ll get the result.

Categories

Subtraction using compliments

Subtraction method mentioned earlier looks good when we do it on paper and pencil but to implement a subtraction method on a digital platform then subtraction using compliments is better and efficient.

r’s compliment:

If we are given numbers M & N with base r, then we can to have to find M – N then we can apply the following method:

If M and N both are positives then

1. Take r’s compliment of subtrahend N
2. Add the compliment to minuend M
3. If we get a carry then discard it otherwise take r’s compliment of the result we get in step 2 and place –ve sign in front of this.

If M is negative and N is positive then i.e. – m – n where m & n are magnitudes of M&N

1. Take r’s compliment of subtrahend N
2. Add the compliment to minuend M
3. If we get no carry then discard it otherwise if carry is 1 then, take r’s compliment of the result we get in step 2 and place –ve sign in front of this.

Eg. 7654310 – 6654310

M=76543

N=66543

10’s compliment of N=33457

As both we ignore carry and answer we get is 0010 which is 2 (not -14) hence it is a wrong answer. It may seem very surprising as we have followed the proper procedure and yet not able to get the answer. Why???????????

Because we have to apply the 2nd rule as M is negative and carry is 1 so  we take 2’s compliment of the answer and final answer we get is – (2’s compliment of 00102) = – 11102 = – 1410

Eg.  – 910 – 1010

Here we see – 1010 can be represented in 2’s compliment in 5 bits so we use 5 bits for both 9= 01001              10=01010

2’s compliment of 9 to represent -9 = 101112

2’s compliment of 10 to represent -10 = 101102

As there is a carry so we’ll not ignore it as M is negative and we’ll calculate 2’s compliment of answer to get the actual answer

Answer= – (2’s compliment of 01101) = – 10011 = – 1910

And we find the correct answer

Eg.  2610 – 610

26 = 11010

6   = 00110

2’s compliment of 6 = 11010

We ignore the carry as M is positive and answer is 10100

Final answer = 10100 = 20 CORRECT

Categories

SUBTRACTION (without using compliment method)

Decimal system: Let’s now analyze the subtraction of decimal systems. For subtraction we first subtract the least significant digit of subtrahend from that of minuend and if least significant digit of subtrahend is greater than that of minuend then we take borrow from the next digit of minuend and add 10 (base) to the previous digit and then subtract and similarly we proceed further.

Binary system:

There are 4 cases of subtraction of bit by bit:

Subtraction    borrow

0 + 0 =      0                     0

1 + 0 =      1                     0

0 + 1 =      1                     1

1 + 1 =      0                   0

Let’s now we do subtraction in binary

Octal system: Let’s now apply the same procedure for the octal system

Hexadecimal: We can apply the same rule to this numbering system also

Categories

Decimal System

1. This is the system which we use in daily life

Value of b=10

e.g.  (456)10

= 4*102 + 5*101 + 6* 100

The weights of the corresponding bits for decimal system are as