TOPICS
Search

Nines' Complement


The nines' complement of a fixed-width decimal numeral is obtained by replacing each digit a by 9-a (Knuth 1998). For a width of d digits, where d is a positive integer, and unsigned value n satisfying 0<=n<10^d, its value is

 C_d(n)=10^d-1-n.

Leading zeros are included in the width. For example, the four-digit numeral 0081 has nines' complement 9918.

Complementing twice restores the original numeral, since C_d(C_d(n))=n. In particular, the all-zero numeral and the all-nine numeral are interchanged. Each complementary pair satisfies n+C_d(n)=10^d-1, a constant-total property used in addition tricks (Numberphile 2013).

This operation is the decimal counterpart of the ones' complement in binary. For n>0, its value is one less than the ten's complement at the same width (Knuth 1998).


See also

Ones' Complement, Ten's Complement

Explore with Wolfram|Alpha

References

Knuth, D. E. "Positional Number Systems." §4.1 in The Art of Computer Programming, Vol. 2: Seminumerical Algorithms, 3rd ed. Reading, MA: Addison-Wesley, 1998. https://www.informit.com/articles/article.aspx?p=2221791.Numberphile. "Number Trick." Featuring J. Grime. Jun. 2, 2013. https://www.youtube.com/watch?v=nd_Z_jZdzP4.

Cite this as:

Weisstein, Eric W. "Nines' Complement." From MathWorld--A Wolfram Resource. https://mathworld.wolfram.com/NinesComplement.html

Subject classifications