One’s and Two’s Complement || Number System || Bcis Notes

One's and Two's Complement || Number System || Bcis Notes

Complements

Complements are used in digital computers for simplifying the subtraction operation and for logical manipulation. There are two types of complements for each base- r system: r’s complement and the second as the (r – 1)’s complement. When the value of the base- r is substituted, the two types are referred to as the One’s complement and Two’s complement for binary numbers, the 10’s complement and 9’s complement for decimal numbers, etc.

(r-1)’s Complement (diminished radix complement.)

(r-1)’s complement of a number N is defined as (rn -1) –N

Where N is the given number

r is the base of the number system

n is the number of digits in the given number

To get the (r-1)’s complement fast, subtract each digit of a number from (r-1).

Example:

– 9’s complement of 83510 is 16410 (Rule: (10n -1) –N)

– One’s complement of 10102 is 01012 (bit by bit complement operation)

 

 

r’s Complement (radix complement)

r’s complement of a number N is defined as rn –N

Where N is the given number

r is the base of a number system

n is the number of digits in the given number

To get the r’s complement fast, add 1 to the low-order digit of its (r-1)’s complement.

Example:

– 10’s complement of 83510 is 16410 + 1 = 16510

– Two’s complement of 10102 is 01012 + 1 = 01102

 

Subtraction with complements

The direct method of subtraction taught in elementary schools uses the borrowed concept. When subtraction is implemented with digital hardware, this method is found to be less efficient than the method that uses complements.

The subtraction of two n-digit unsigned numbers M N in base-r can be done as follows:

  1. Add the minuend M to the r’s complement of the subtrahend N. This performs M + (rn –N) = M N + r”.
  2. If M >= N, the sum will produce an end carry, r”, which is discarded; what is left is the result M N.
  3. If M < N, the sum does not produce an end carry and is equal to rn (N M), which is the r’s complement of (N M). To obtain the answer in a familiar form, take the r’s complement of the sum and place a negative sign in front.

One's and Two's Complement

Notes:

HEY! M has 5 digits and N has only 4 digits. Both numbers must have the same number of digits; so we can write N as 03250. Taking the 10’s complement of N produces a 9 in the most significant position. The occurrence of the end carries signifies that M >= N and the result is positive.

Example II:

One's and Two's Complement

Example III:

One's and Two's Complement

Example IV: Repeating Example III using 1’s complement.

One's and Two's Complement

 

You may like this Binary code

Be the first to comment

Leave a Reply

Your email address will not be published.


*