Skip to main content

Complement of a Number

Subtraction of Binary Numbers  ; Octal and Hexadecimal Number  ; Convert Decimal to Binary

Complements

Complements are used in digital computers for simplifying the subtraction operation and for logical manipulations. There are two types of complements for each base-r system: (1) the r’s complement and (2) the (r-1)’s complement. When the value of the base is substituted, the two types receive the names 2’s and 1’s complement for binary numbers,  10’s and 9’s complement for decimal numbers.


The r’s Complement

Given a positive number N in base r with an integer part of n digits, the r’s complement of N is defined as rn  - N for N is not equal to 0 and 0 for N = 0. The following numerical example will help clarify the definition.

The 10’s complement of (52520)10 is 105 – 52520 = 47480

The number of digits in the number is n= 5

The 10’s complement of (0.3267)10 is 1 – 0.3267 = 0.6733

No integer part, so 10n = 100 = 1

The 10’s complement of (25.639)10 is 102 – 25.639 = 74.361.

The 2’s complement of (101100)2 is 26 – (101100)2 = (1000000 - 101100)2 = 010100

The 2’s complement of (0.0110)2 is (1 – 0.0110)2 = 0.1010

From the definition and the examples, it is clear that the 10’s complement of a decimal number can be formed by leaving all least significant zeros unchanged, subtracting the first nonzero least significant digit from 10, and then subtracting all other higher significant digits from9. The 2’s complement can be formed by leaving all least significant zeros and the first nonzero digits unchanged, and then replacing 1’s by 0’s and 0’s by 1’s in all other higher significant digits. A third simpler method for obtaining the r’s complement is given after the definition of the (r-1)’s complement.

                The examples listed here use numbers with r = 10(for decimal) and r = 2(for binary) because these are the two bases of most interest to us.

 

The (r - 1)’s Complement

Given a positive number N in base r with an integer part of n digits and a fraction part of m digits, the (r - 1)’s complement of N is defined as rm – r-m – N. Some numerical examples follow:

The 9’s complement of (52520)10 is (105 – 1 - 52520) = 99999 – 52520 = 47479

No fraction part, so 10-m = 100 = 1

The 9’s complement of (0.3267)10 is (1 – 10-4 – 0.3267) = 0.9999 – 0.3267 = 0.6732

No integer part, so 10n = 100 = 1

The 9’s complement of (25.639)10 is (102 – 10-3 – 25.639) = 99.999 – 25.639 = 74.360

The 1’s complement of (101100)2 is (26 - 1) – (101100) = (111111 - 101101)2 = 010011

The 1’s complement of (0.0110)2 is (1 – 2-4) – (0.0110) = (0.1111 – 0.0110)2 = 0.1001

From the examples, we see that the 9’s complement of a decimal number is formed simply by subtracting every digit by 9. The 1’s complement of a binary number is even simpler to form: the 1’s are changed to 0’s and 0’s are changed to 1’s. Since the (r - 1)’s complement is very easily obtained, it is sometimes convenient to use it when the r’s complement is desired. From the definitions and from a comparison of the results obtained in the examples, it follows that the r’s complement can be obtained from the (r - 1)’s complement after the addition of r-m to the least significant digit. For example, the 2’s complement of 10110100 is obtained from the 1’s complement 01001011 by adding 1 to give 01001100.

Short Trick to find 1’s and 2’s complement in Binary

1’s complement – Replace 0 by 1 and 1 by 0

2’s complement – Add 1 after replacing 0 by 1 and 1 by 0

 

     

 

 


Comments

Popular posts from this blog

Rules of divisibility part -1

Rules of divisibility In Vedic mathematics, it can be determined whether any part of any other number can be given completely without dividing it by several methods. These methods are based on the law of divisibility. By using these rules, calculations related to factors, parts etc. are simplified. Law of divisibility by number 2 :- If unit digit of given number is divisible by 2 then the given number is divisible by 2 also.                                                                 or  If unit digit of given number is 0,2,4,6 or 8 , then given number is divisible by 2. Example :- 10 ,32 ,74 ,108 ,2058 etc. Law of divisibility by number 3 :- If the sum of digits of given number is divisible by 3, then the number is divisible by 3 also. Illustration 1:-  In 546532 sum of digits=5+4+6+5+3+2=25 25 is not divisible...

Convert Decimal to Binary and Octal

Complement of a Number    Number System    Types of Number system In our previous article, we had discussed Convert any number into Decimal Number. Now, In this article we can easily understand how to convert Decimal Number into other Number Note : The Rule is very simple. Any number which you want convert Decimal to required format. Just divide by its base to this number and remainder is taken from bottom to top. Let’s understand with some examples Convert Decimal to Binary Ex 1. Convert (41) 10 into Binary Number Sol. 41 is divide by 2 because the base of binary number is 2       Integer quotient    Quotient      Remainder        41 / 2                       20                 ...