开发者

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 compl开发者_运维百科ements but no effect.

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


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.


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.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜