The nines' complement of a fixed-width decimal numeral is obtained by replacing each digit by
(Knuth 1998). For a width of
digits, where
is a positive integer,
and unsigned value
satisfying
,
its value is
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 . In particular, the all-zero
numeral and the all-nine numeral
are interchanged. Each complementary pair satisfies
, a constant-total property used in addition
tricks (Numberphile 2013).
This operation is the decimal counterpart of the ones' complement in binary. For , its value is one less than the ten's
complement at the same width (Knuth 1998).