Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find N's complement of a number?

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?

like image 571
Renjith G Avatar asked Feb 20 '10 18:02

Renjith G


2 Answers

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.

like image 170
Mark Byers Avatar answered Oct 28 '22 20:10

Mark Byers


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.
like image 24
konduri Sriram Avatar answered Oct 28 '22 21:10

konduri Sriram