How to find N's complement of a number?

25,241

Solution 1

The nines' complement in base 10 is found by subtracting each digit from 9.

So 45 (= ...000045) becomes 54 (= ...999954).

Ten's complement is just nines' complement plus 1. So ...000045 becomes (...999954 + 1) = ...999955.

More info on Wikipedia.

Solution 2

n's complement use: (simple three step method).

Suppose 512 - 96 = ? (both numbers are given in base n, say base:14).

  1. Find n-1 complement of 96 (second number which is to be subtracted). 13's complement of 099 is DDD - 096 = D47 (since A=10, B=11, C=12, D=13).

  2. Find n's complement by adding 1 to n - 1's complement value. 14's complement is D47 + 1 = D48.

  3. Add the first number (512) with the n's complement (D48) and leave the carry. 512 + D48 = 45A (carry 1 removed).

CHECK:

512(14 base) = 996(10 base)
96(14 base) = 132(10 base)
996-132 = 864(base 10) = 45A(base 14) HENCE CHECKED.
Share:
25,241
Renjith G
Author by

Renjith G

Working as a system programmer

Updated on December 18, 2020

Comments

  • Renjith G
    Renjith G over 3 years

    I want to find 9's complement of number but failed.

    I tried it with the methods of 1's and 2's complements but no effect.

    What is common method to find out the N's complement of a number?