In this post, a general method of finding complement with any arbitrary base is discussed.
Steps to find (b-1)’s complement: To find (b-1)’s complement,
- Subtract each digit of the number from the largest number in the number system with base .
- For example, if the number is a three digit number in base 9, then subtract the number from 888 as 8 is the largest number in base 9 number system.
- The obtained result is the (b-1)’s (8’s complement) complement.
Steps to find b’s complement: To find b’s complement, just add 1 to the calculated (b-1)’s complement.
Now this holds true for any base in the number system that exists. It can be tested with familiar bases that is the 1’s and 2’s complement.
Let the number be 10111 base 2 (b=2) Then, 1's complement will be 01000 (b-1) 2's complement will be 01001 (b) Taking a number with Octal base: Let the number be -456. Then 7's compliment will be 321 and 8's compliment will be 322
Below is the implementation of above idea:
- Given a number N in decimal base, find number of its digits in any base (base b)
- C++ program to find all numbers less than n, which are palindromic in base 10 and base 2.
- 9's complement of a decimal number
- 10's Complement of a decimal number
- Previous number same as 1's complement
- 1's and 2's complement of a Binary Number
- 8085 program to find 1's and 2's complement of 8-bit number
- 8085 program to find 1’s and 2’s complement of 16-bit number
- Check if binary representation of a given number and its complement are anagram
- Interface 8255 with 8085 microprocessor for 1’s and 2’s complement of a number
- Pandigital number in a given base
- Check if a number is in given base or not
- Check if a number N starts with 1 in b-base
- Check whether a number has consecutive 0's in the given base or not
- What’s difference between 1's Complement and 2's Complement?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.