+ All Categories
Home > Technology > Complements

Complements

Date post: 29-Jun-2015
Category:
Upload: sudheesh-s-madhav
View: 1,183 times
Download: 1 times
Share this document with a friend
Description:
1's and 2's complements
Popular Tags:
18
Complements digital electronics - 13IDP14 13IDP14
Transcript
Page 1: Complements

Complements

digital electronics - 13IDP1413IDP14

Page 2: Complements

Subtraction using addition Conventional addition (using carry) is

easily implemented in digital computers. However; subtraction by borrowing is

difficult and inefficient for digital computers.

Much more efficient to implement subtraction using ADDITION OF the COMPLEMENTS of numbers.

Page 3: Complements

Complements of numbers

(r-1 )’s Complement

•Given a number N in base r having n digits, •the (r- 1)’s complement of N is defined as

(rn - 1) - N

•For decimal numbers the base or r = 10 and r- 1= 9,

•so the 9’s complement of N is (10n-1)-N

•99999……. - N

Digit n

Digit n-1

Next digit

Next digit

First digit

9 9 9 9 9

-

Page 4: Complements

2- Find the 9’s complement of 546700 and 12389

The 9’s complement of 546700 is 999999 - 546700= 453299

and the 9’s complement of 12389 is 99999- 12389 = 87610.

9’s complement Examples

5 4 6 7 0- 0

9 9 9 9 9 9

4 5 3 2 9 9

1 2 3 8- 9

9 9 9 9 9

8 7 6 1 0

Page 5: Complements

l’s complement

For binary numbers, r = 2 and r — 1 = 1,

r-1’s complement is the l’s complement.

The l’s complement of N is (2n - 1) - N.

Digit n

Digit n-1

Next digit

Next digit

First digit

1 1 1 1 1

Bit n-1 Bit n-2 ……. Bit 1 Bit 0

-

Page 6: Complements

l’s complement

Find r-1 complement for binary number N with four binary digits.

r-1 complement for binary means 2-1 complement or 1’s complement.

n = 4, we have 24 = (10000)2 and 24 - 1 = (1111)2.

The l’s complement of N is (24 - 1) - N. = (1111) - N

Page 7: Complements

The complement 1’s of1011001 is 0100110

0 1 1 0 0- 1

1 1 1 1 1 1

1 0 0 1 1 0

0 0 1 1 1- 1

1 1 1 1 1 1

1 1 0 0 0 0

1

1

0

The 1’s complement of0001111 is 1110000

0

1

1

l’s complement

Page 8: Complements

r’s Complement

•Given a number N in base r having n digits, •the r’s complement of N is defined as

rn - N.

•For decimal numbers the base or r = 10,

•so the 10’s complement of N is 10n-N.

•100000……. - N

Digit n

Digit n-1

Next digit

Next digit

First digit

0 0 0 0 0

-1

Page 9: Complements

10’s complement Examples

Find the 10’s complement of 546700 and 12389

The 10’s complement of 546700 is 1000000 - 546700= 453300

and the 10’s complement of 12389 is

100000 - 12389 = 87611.

Notice that it is the same as 9’s complement + 1.

5 4 6 7 0- 0

0 0 0 0 0 0

4 5 3 3 0 0

1 2 3 8- 9

1 0 0 0 0 0

8 7 6 1 1

1

Page 10: Complements

For binary numbers, r = 2,

r’s complement is the 2’s complement.

The 2’s complement of N is 2n - N.

2’s complement

Digit n

Digit n-1

Next digit

Next digit

First digit

0 0 0 0 0

-1

Page 11: Complements

2’s complement Example

The 2’s complement of1011001 is 0100111

The 2’s complement of0001111 is 1110001

0 1 1 0 0- 1

0 0 0 0 0 0

1 0 0 1 1 1

0 0 1 1 1- 1

1 1 0 0 0 1

1

0

0

0

1

1

0 0 0 0 0 001

Page 12: Complements

Fast Methods for 2’s Complement

Method 1:The 2’s complement of binary number is obtained by adding 1 to the l’s complement value.Example:1’s complement of 101100 is 010011 (invert the 0’s and 1’s)2’s complement of 101100 is 010011 + 1 = 010100

Page 13: Complements

Fast Methods for 2’s Complement

 Method 2:The 2’s complement can be formed by leaving all least significant 0’s and the first 1 unchanged, and then replacing l’s by 0’s and 0’s by l’s in all other higher significant bits.

Example:The 2’s complement of 1101100 is

0010100 Leave the two low-order 0’s and the first 1 unchanged, and then replacing 1’s by 0’s and 0’s by 1’s in the four most significant bits.

Page 14: Complements

Examples– Finding the 2’s complement of (01100101)2

• Method 1 – Simply complement each bit and then add 1 to the result. (01100101)2

[N] = 2’s complement = 1’s complement (10011010)2 +1

=(10011011)2

• Method 2 – Starting with the least significant bit, copy all the bits up to and including the first 1 bit and then complement the remaining bits.

N = 0 1 1 0 0 1 0 1

[N] = 1 0 0 1 1 0 1 1

Page 15: Complements

Subtraction of Unsigned Numbers using r’s complement

Subtract N from M : M – N

r’s complement N (rn – N )

add M to ( rn – N ) : Sum = M + ( r n – N)

 take r’s complement (If M N, the negative sign will produce an end carry rn we need to take the r’s complement again.)

Page 16: Complements

Subtraction of Unsigned Numbers using r’s complement

(1) if M N, ignore the carry without taking complement of sum.

(2) if M < N, take the r’s complement of sum and place negative sign in front of sum. The answer is negative.

Page 17: Complements

Example 1 (Decimal unsigned numbers),  perform the subtraction 72532 - 13250 = 59282.  M > N : “Case 1” “Do not take complement of sumand discard carry”The 10’s complement of 13250 is 86750. Therefore:

M = 7253210’s complement of N =+86750

Sum= 159282Discard end carry 105= - 100000Answer = 59282 no complement

Page 18: Complements

Example 2;Now consider an example with M <N. The subtraction 13250 - 72532 produces negative 59282. Using the procedure with complements, we have 

M = 1325010’s complement of N = +27468

Sum = 40718

Take 10’s complement of Sum = 100000

-40718

The number is : 59282

Place negative sign in front of the number: -59282


Recommended