![]() |
VOOZH | about |
In this post, a general method of finding complement with any arbitrary base is discussed.
Remember: It is recommended to go through below as follows:
Steps to find (b-1)’s complement: To find (b-1)’s 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.
Example:
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 complement will be 321 and 8's complement will be 322
Below is the implementation of the above idea as follows:
41 42
Time Complexity: O(log n)
Auxiliary Space: O(1)