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:

Take (r – 1) ’s compliment of subtrahend N

Add it to minuend M

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:

Take (r – 1) ’s compliment of subtrahend N

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. 1010100_{2} – 1000100_{2}

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

Eg. 1000100_{2} – 1010100_{2}

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

So answer is -0010000

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.

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

Take r’s compliment of subtrahend N

Add the compliment to minuend M

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

Take r’s compliment of subtrahend N

Add the compliment to minuend M

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. 76543_{10} – 66543_{10}

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 2^{nd} 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 0010_{2}) = – 1110_{2} = – 14_{10}

Eg. – 9_{10} – 10_{10}

Here we see – 10_{10} 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 = 10111_{2}

2’s compliment of 10 to represent -10 = 10110_{2}

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

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

r’s compliment

(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 10^{4}– 5432 = 10000 – 5432 = (4568)_{ 10}

[value of n is 4]

10’s compliment of number (0.5432)_{ 10} is 10^{0}– 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 10^{2}– 54.32 = 100 – 54.32 = (45.68)_{ 10} [value of n is 2]

2’s compliment of number (110.01)_{ 2} is (2^{3})_{2}– 110.01_{2}= 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^{n }– r^{-m}– N

9’s compliment of number (5432)_{ 10} is 10^{4}– 10^{0} – 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 10^{0}– 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^{2 }– 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 (2^{3})_{10}– (2^{-2})_{10 }– 110.01_{2}= 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 }– N and compliment of compliment is r^{n }– (r^{n }– 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^{n }– r^{-m} – N and compliment of compliment is r^{n }– r^{-m}– (r^{n }– 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 4^{th} 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

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

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

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.

Hexadecimal and octal to binary:

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.

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.

Let the decimal number be 26 so we can convert it to octal by dividing the number with the base=8 and then write the quotient and remainder as shown below and then again divide the quotient with the base till we get quotient as zero. This method is also called Oct-dabble method.

Conversion of fraction from decimal to octal is similar to the one for binary and follows the following procedure: just multiply the fraction by base=8 and integer which we get to left of the decimal point is saved

Fraction is 0.3875

0.3875 * 8 =3.1000 =3 + 0.1000 a_{-1}=3

0.1000 * 8 =0.8000 =0 + 0.8000 a_{-2}=0

0.8000 * 8 =6.4000 =6 + 0.4000 a_{-3}=6

0.4000 * 8 =3.2000 =3 + 0.2000 a_{-4}=3

And let me re-write the same facts about the procedure followed above. It may go on till we get the fractional part as zero but this may not be possible in finite no of bits hence usually we restrict the no of bits to represent the value to a finite value and get an approximate value…

So the (0.3875)_{10} = 0.a_{-1} a_{-2} a_{-3} a_{-4 }……= (0.3063….) _{8} = (0.3063)_{8}

If we convert the value (0.3063)_{2} back to decimal

=3 * 8^{-1} + 0 * 8^{-2} + 6 * 8^{-3} + 3 *8^{-4} =0.3777 which is only approximate value of the actual value. So we see the equivalent we get in nay number system for a fraction may only be an approximate value. The same again that we may increase the no of bits to increase the accuracy.