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 by 3, Hence the number 546532 is not divisible by 3. Illustration 2:-  In  287286 sum of digits=2+8+7+2+8+6=33 33 is divisible by 3, Hence the number 287286 is divisibl

Octal and Hexadecimal Number

Complement of a Number    Types of Number system    Convert Decimal to Binary If you are new to this article, I strongly recommend to read our previous article before preceding this. In our previous article, we had already seen that binary number has a base of 2. It means that binary number contains 2 1 = 2 combinations which are 0 and 1. Similarly, Octal and Hexadecimal number has a fixed number of combinations. As we earlier know that octal has a base 8, then it contains 8 digits through 0 to 7 which means 2 3 =8 combinations and Hexadecimal has a base 16 which means it has 2 4 =16 combinations.                 If you are focusing on a sequence i.e. octal, hexadecimal. They are the combinations of increasing power of 2. Octal – 2 3 , Hexadecimal - 2 4 This power indicates how many bits are in a number for a particular number system Octal has 3 bits Hexadecimal has 4 bits This can be clear understand by following diagram-   Explain – In this diagram, first we co

Hunters of the Animal World

    In the cycle of life, predators always occupy an important position. They are killers. But they kill, only to 'kill' their hunger. In fact, the story of the animal kingdom is full of predators trying to catch prey, and the prey trying to outwit predators. It is the balance between the two that takes the drama of life forward. In the wild, there is no place for the weak, whether it's the predator or the prey, and only the fittest survives. The hunters keep populations healthy by weeding out the old and the sick. Of course, there are also creatures that steal the prey caught by others, like hyenas.      We have collected information about some animals for which you must know. 1 . Bengal Tigers : The Bengal Tiger is found in the rainforests and grasslands of Bangladesh, Bhutan Burma, China, India and Nepal. Bengal tigers are extremely large, and the males are up to 3 meters in length. The Bengal tiger's fur is orange brown, with black stripes. It hunts deer, pigs, a