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

## COMPLIMENTS

For a number system with base r (with r > 1), there are two types of compliments:

1. r’s compliment
2. (r-1) ‘s compliment

r’s Compliment: If we have a positive number N with integer part of n digits  then we define r’s compliment  as

10’s compliment of number (5432) 10 is 104– 5432 = 10000 – 5432 = (4568) 10

[value of n is 4]

10’s compliment of number (0.5432) 10 is 100– 0.5432 = 1 – 0.5432 = (0.4568) 10

[value of n is 0 as there is no integer  part in this number]

10’s compliment of number (54.32) 10 is 102– 54.32 = 100 – 54.32 = (45.68) 10             [value of n is 2]

2’s compliment of number (110.01) 2 is (23)2– 110.012= 1000 – 110.01 = 001.11         [value of n is 3]

Eg. Find 2’s compliment of (110.01) 2 (value from above example)

Ans: Following the rule we get the answer as 000.1110

(r-1) ‘s compliment: If we have a positive number N with base r and integer part with digits n and fractional part of m digits,  we define (r-1) ‘s compliment as r– r-m– N

9’s compliment of number (5432) 10 is 104– 100 – 5432 = 10000 – 1 –  5432 = (4567) 10

[Value of n is 4 and of m is 0]

9’s compliment of number (0.5432) 10 is 100– 10-4 – 0.5432 = 1 – 0.0001 – 0.5432 = (0.4567) 10

[Value of n is 0 as there is no integer part in this number and of m is 4]

9’s compliment of number (54.32) 10 is 10– 10-2 – 54.32 = 100 – 0.01 – 54.32 = (45.67) 10 [Value of n is 2 and of m is 2]

1’s compliment of number (110.01) 2 is (23)10– (2-2)10 – 110.012= 1000 – 0.01 – 110.01 = 001.10      [Value of n is 3 and of m is 2]

Applying the rule to above example we get the answer as 001.10, the sameJ

Relation between the r’s Compliment and (r-1) ‘s compliment: We can get r’s Compliment from (r-1) ‘s compliment by just adding r-m  and vice-versa by subtracting   r-m

Compliment of compliment: If we take r’s compliment of r’s compliment we get the original number as

Let the original number be N

So r’s compliment is r– N and compliment of compliment is r– (r– N) = N  which is the original number

and the same is for (r-1) ‘s compliment.

Let the original number be N

So r’s compliment is r– r-m – N and compliment of compliment is r– r-m – (r– r-m – N ) = N  which is the original number

1’s compliment and 2’s compliment:  Following table would show the representation of decimal -7 to +8 in 1’s and 2’s compliment. In the signed number , we take the 4th bit as signed bit and make this bit one(‘1’) when ever we have negative number & make it zero(‘0’) when we have a positive number and rest of  the 3 bits are used to represent magnitude.

Comparison of 1’s compliment and 2’s compliment:

• 1’s compliment is easier to implement than 2’s compliment
• While for the subtraction, 2’s compliment is better because for 2’s compliment we need only 1 arithmetic operation while 2 arithmetic operations are needed for 1’s compliment.
• 2’s compliment has only one representation for zero while  1’s compliment has two representation for zero as shown above
Categories

## MULTIPLICATION & DIVISION

We similarly can apply the procedures of addition or subtraction during multiplication and division and get the results for multiplication and division of different numbering systems

MULTIPLICATION:

Procedure of multiplication is same as that of decimal

Generalized multiplication of two 4-digit numbers is as follow:

Eg.  910 * 810

910= 10012

810 =10002

Similarly we can do it for fractional binary numbers; we just have to adjust binary point to the numbers of places equal to addition of numbers of places of the multiplicand and multiplier

If we implement the general multiplication method of two 4-bit numbers then we need 16 AND gates to calculate those 16 terms of multiplication and also full adders to add the terms and the carries flying from one column to another as shown below:

DIVISON: Similar to multiplication we can do division as shown below:

Q- Divide 4210 by 610 using binary division

4210 =1010102

610 =1102

Hence quotient is 1112 and remainder is 0002

Division and multiplication for octal and hexadecimal number system:

We can convert the octal and hexadecimal numbers to binary and perform the multiplication and division as it would be very cumbersome to do it by keeping the numbers in their given form

Q- Multiply F016with 4516

F016=1111 00002

4516=0100 01012

And we can perform the multiplication in binary form.

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: Although all of us are doing addition in decimal system since years and this may look a bit odd to study this again but I’ll still emphasize to study it further. Let us analyze the addition for decimal system.  For addition we firstly add least significant digits and keep the least significant digit of the result we get, in the least significant position of the sum and rest of the part is taken as carry and added to the next digits as:

But let me put it in another way which is actually a generalized method for addition. We first add least significant digits and if result we get is equal to or more that ‘10’ (base) then we’ll subtract ‘10’ (b) from the result as many times we can and remainder is then saved in the sum register while the number of times we can subtract is taken as carry.

Now we’ll take this method and apply it to any system for addition Binary system:There are 4 cases of addition of bit by bit:                Sum       carry0 + 0 =     0                01 + 0 =      1               00 + 1 =      1               01 + 1 =      1             1
Categories

## Binary to octal & hexadecimal And Vice-versa

To convert the number from binary to octal we make groups of 3 bits starting from the decimal point (in case of fractions)  and from right most bit (in case of integers) and write the corresponding octal equivalent of those 3 bits every time.

The process of replacing the long strings of 1 & o with the shorter strings like Octal & hexadecimal equivalents is known as chunking.

To do the above we convert the digits into their corresponding binary equivalents of 3-bits and 4-bits for octal and hexadecimal numbers respectively.

Categories

Decimal to Hexadecimal: following the same procedure

Convert 26 decimal to hexadecimal: This method is also called Hex-dabble method.

We can convert a fraction from a decimal to hexadecimal form by multiplying wit base and following the same procedure.

Fraction is 0.3875

0.3875 * 16                          =6.2000                =6 + 0.2000         a-1=6

0.2000 * 16                          =3.2000                =3 + 0.2000         a-2=3

0.2000 * 16                          =3.2000                =3 + 0.2000         a-3=3

Similarly a-4=3, a-5=3, a-6=3 so on…….

Hence the hexadecimal equivalent is 0.63333…

Categories

## Binary to octal conversion

To convert the number from binary to octal we make groups of 3 bits starting from the decimal point (in case of fractions)  and from right most bit (in case of integers) and write the corresponding octal equivalent of those 3 bits every time.

The process of replacing the long strings of 1 & o with the shorter strings like Octal & hexadecimal equivalents is known as chunking.

Categories

Following the same procedure as earlier

Convert 26 decimal to hexadecimal: This method is also called Hex-dabble method.

We can convert a fraction from a decimal to hexadecimal form by multiplying wit base and following the same procedure.

Fraction is 0.3875

0.3875 * 16                          =6.2000                =6 + 0.2000         a-1=6

0.2000 * 16                          =3.2000                =3 + 0.2000         a-2=3

0.2000 * 16                          =3.2000                =3 + 0.2000         a-3=3

Similarly a-4=3, a-5=3, a-6=3 so on…….

Hence the hexadecimal equivalent is 0.63333…