<s>
In	O
mathematics	O
and	O
computing	O
,	O
the	O
method	B-Algorithm
of	I-Algorithm
complements	I-Algorithm
is	O
a	O
technique	O
to	O
encode	O
a	O
symmetric	O
range	O
of	O
positive	O
and	O
negative	O
integers	O
in	O
a	O
way	O
that	O
they	O
can	O
use	O
the	O
same	O
algorithm	O
(	O
hardware	O
)	O
for	O
addition	O
throughout	O
the	O
whole	O
range	O
.	O
</s>
<s>
The	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
a	O
number	O
given	O
in	O
decimal	B-Application
representation	O
is	O
formed	O
by	O
replacing	O
each	O
digit	O
with	O
nine	O
minus	O
that	O
digit	O
.	O
</s>
<s>
To	O
subtract	O
a	O
decimal	B-Application
number	O
y	O
(	O
the	O
subtrahend	O
)	O
from	O
another	O
number	O
x	O
(	O
the	O
minuend	O
)	O
two	O
methods	O
may	O
be	O
used	O
:	O
</s>
<s>
In	O
the	O
first	O
method	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
x	O
is	O
added	O
to	O
y	O
.	O
</s>
<s>
Then	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
the	O
result	O
obtained	O
is	O
formed	O
to	O
produce	O
the	O
desired	O
result	O
.	O
</s>
<s>
In	O
the	O
second	O
method	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
y	O
is	O
added	O
to	O
x	O
and	O
one	O
is	O
added	O
to	O
the	O
sum	O
.	O
</s>
<s>
The	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
plus	O
one	O
is	O
known	O
as	O
the	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
.	O
</s>
<s>
The	O
method	B-Algorithm
of	I-Algorithm
complements	I-Algorithm
can	O
be	O
extended	O
to	O
other	O
number	O
bases	O
(	O
radices	O
)	O
;	O
in	O
particular	O
,	O
it	O
is	O
used	O
on	O
most	O
digital	O
computers	O
to	O
perform	O
subtraction	O
,	O
represent	O
negative	O
numbers	O
in	O
base	O
2	O
or	O
binary	O
arithmetic	O
and	O
test	O
underflow	O
and	O
overflow	O
in	O
calculation	O
.	O
</s>
<s>
The	O
radix	B-Algorithm
complement	I-Algorithm
of	O
an	O
digit	O
number	O
in	O
radix	O
is	O
defined	O
as	O
.	O
</s>
<s>
In	O
practice	O
,	O
the	O
radix	B-Algorithm
complement	I-Algorithm
is	O
more	O
easily	O
obtained	O
by	O
adding	O
1	O
to	O
the	O
diminished	B-Algorithm
radix	I-Algorithm
complement	I-Algorithm
,	O
which	O
is	O
.	O
</s>
<s>
While	O
this	O
seems	O
equally	O
difficult	O
to	O
calculate	O
as	O
the	O
radix	B-Algorithm
complement	I-Algorithm
,	O
it	O
is	O
actually	O
simpler	O
since	O
is	O
simply	O
the	O
digit	O
repeated	O
times	O
.	O
</s>
<s>
Knowing	O
this	O
,	O
the	O
diminished	B-Algorithm
radix	I-Algorithm
complement	I-Algorithm
of	O
a	O
number	O
can	O
be	O
found	O
by	O
complementing	O
each	O
digit	O
with	O
respect	O
to	O
,	O
i.e.	O
</s>
<s>
The	O
subtraction	O
of	O
from	O
using	O
diminished	B-Algorithm
radix	I-Algorithm
complements	I-Algorithm
may	O
be	O
performed	O
as	O
follows	O
.	O
</s>
<s>
Add	O
the	O
diminished	B-Algorithm
radix	I-Algorithm
complement	I-Algorithm
of	O
to	O
to	O
obtain	O
or	O
equivalently	O
,	O
which	O
is	O
the	O
diminished	B-Algorithm
radix	I-Algorithm
complement	I-Algorithm
of	O
.	O
</s>
<s>
Further	O
taking	O
the	O
diminished	B-Algorithm
radix	I-Algorithm
complement	I-Algorithm
of	O
results	O
in	O
the	O
desired	O
answer	O
of	O
.	O
</s>
<s>
Alternatively	O
using	O
the	O
radix	B-Algorithm
complement	I-Algorithm
,	O
may	O
be	O
obtained	O
by	O
adding	O
the	O
radix	B-Algorithm
complement	I-Algorithm
of	O
to	O
to	O
obtain	O
or	O
.	O
</s>
<s>
In	O
the	O
decimal	B-Application
numbering	O
system	O
,	O
the	O
radix	B-Algorithm
complement	I-Algorithm
is	O
called	O
the	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
and	O
the	O
diminished	B-Algorithm
radix	I-Algorithm
complement	I-Algorithm
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
.	O
</s>
<s>
In	O
binary	O
,	O
the	O
radix	B-Algorithm
complement	I-Algorithm
is	O
called	O
the	O
two	B-General_Concept
's	I-General_Concept
complement	I-General_Concept
and	O
the	O
diminished	B-Algorithm
radix	I-Algorithm
complement	I-Algorithm
the	O
ones	O
 '	O
complement	O
.	O
</s>
<s>
Some	O
people	O
,	O
notably	O
Donald	O
Knuth	O
,	O
recommend	O
using	O
the	O
placement	O
of	O
the	O
apostrophe	O
to	O
distinguish	O
between	O
the	O
radix	B-Algorithm
complement	I-Algorithm
and	O
the	O
diminished	B-Algorithm
radix	I-Algorithm
complement	I-Algorithm
.	O
</s>
<s>
In	O
this	O
usage	O
,	O
the	O
four	O
's	O
complement	O
refers	O
to	O
the	O
radix	B-Algorithm
complement	I-Algorithm
of	O
a	O
number	O
in	O
base	O
four	O
while	O
fours	O
 '	O
complement	O
is	O
the	O
diminished	B-Algorithm
radix	I-Algorithm
complement	I-Algorithm
of	O
a	O
number	O
in	O
base	O
5	O
.	O
</s>
<s>
Most	O
writers	O
use	O
one	O
's	O
and	O
nine	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
,	O
and	O
many	O
style	O
manuals	O
leave	O
out	O
the	O
apostrophe	O
,	O
recommending	O
ones	O
and	O
nines	B-Algorithm
complement	I-Algorithm
.	O
</s>
<s>
The	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
a	O
decimal	B-Application
digit	O
is	O
the	O
number	O
that	O
must	O
be	O
added	O
to	O
it	O
to	O
produce	O
9	O
;	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
3	O
is	O
6	O
,	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
7	O
is	O
2	O
,	O
and	O
so	O
on	O
,	O
see	O
table	O
.	O
</s>
<s>
To	O
form	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
a	O
larger	O
number	O
,	O
each	O
digit	O
is	O
replaced	O
by	O
its	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
.	O
</s>
<s>
Compute	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
the	O
minuend	O
,	O
873	O
.	O
</s>
<s>
Add	O
that	O
to	O
the	O
subtrahend	O
218	O
,	O
then	O
calculate	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
the	O
result	O
.	O
</s>
<s>
Compute	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
218	O
,	O
which	O
is	O
781	O
.	O
</s>
<s>
Next	O
,	O
the	O
sum	O
of	O
and	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
is	O
taken	O
:	O
</s>
<s>
The	O
last	O
step	O
of	O
adding	O
1	O
could	O
be	O
skipped	O
if	O
instead	O
the	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
of	O
y	O
was	O
used	O
in	O
the	O
first	O
step	O
.	O
</s>
<s>
The	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
999990	O
is	O
000009	O
.	O
</s>
<s>
Replacing	O
00391	O
with	O
its	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
and	O
adding	O
1	O
produces	O
the	O
sum	O
:	O
</s>
<s>
The	O
method	B-Algorithm
of	I-Algorithm
complements	I-Algorithm
is	O
especially	O
useful	O
in	O
binary	O
(	O
radix	O
2	O
)	O
since	O
the	O
ones	O
 '	O
complement	O
is	O
very	O
easily	O
obtained	O
by	O
inverting	O
each	O
bit	O
(	O
changing	O
'	O
0	O
 '	O
to	O
'	O
1	O
 '	O
and	O
vice	O
versa	O
)	O
.	O
</s>
<s>
Adding	O
1	O
to	O
get	O
the	O
two	B-General_Concept
's	I-General_Concept
complement	I-General_Concept
can	O
be	O
done	O
by	O
simulating	O
a	O
carry	O
into	O
the	O
least	O
significant	O
bit	O
.	O
</s>
<s>
The	O
method	B-Algorithm
of	I-Algorithm
complements	I-Algorithm
normally	O
assumes	O
that	O
the	O
operands	O
are	O
positive	O
and	O
that	O
y	O
≤	O
x	O
,	O
logical	O
constraints	O
given	O
that	O
adding	O
and	O
subtracting	O
arbitrary	O
integers	O
is	O
normally	O
done	O
by	O
comparing	O
signs	O
,	O
adding	O
the	O
two	O
or	O
subtracting	O
the	O
smaller	O
from	O
the	O
larger	O
,	O
and	O
giving	O
the	O
result	O
the	O
correct	O
sign	O
.	O
</s>
<s>
For	O
example	O
,	O
(	O
in	O
decimal	B-Application
)	O
:	O
</s>
<s>
The	O
expected	O
answer	O
is	O
−144	O
,	O
which	O
is	O
n't	O
as	O
far	O
off	O
as	O
it	O
seems	O
;	O
856	O
happens	O
to	O
be	O
the	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
of	O
144	O
.	O
</s>
<s>
Represent	O
negative	O
numbers	O
as	O
radix	B-Algorithm
complements	I-Algorithm
of	O
their	O
positive	O
counterparts	O
.	O
</s>
<s>
Numbers	O
less	O
than	O
are	O
considered	O
positive	O
;	O
the	O
rest	O
are	O
considered	O
negative	O
(	O
and	O
their	O
magnitude	O
can	O
be	O
obtained	O
by	O
taking	O
the	O
radix	B-Algorithm
complement	I-Algorithm
)	O
.	O
</s>
<s>
For	O
example	O
,	O
numbers	O
in	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
notation	O
are	O
positive	O
if	O
the	O
first	O
digit	O
is	O
0	O
,	O
1	O
,	O
2	O
,	O
3	O
,	O
or	O
4	O
,	O
and	O
negative	O
if	O
5	O
,	O
6	O
,	O
7	O
,	O
8	O
,	O
or	O
9	O
.	O
</s>
<s>
Indeed	O
,	O
two	B-General_Concept
's	I-General_Concept
complement	I-General_Concept
is	O
used	O
in	O
most	O
modern	O
computers	O
to	O
represent	O
signed	O
numbers	O
.	O
</s>
<s>
But	O
since	O
taking	O
the	O
radix	B-Algorithm
complement	I-Algorithm
requires	O
adding	O
1	O
,	O
it	O
is	O
difficult	O
to	O
do	O
directly	O
.	O
</s>
<s>
And	O
if	O
not	O
,	O
the	O
1	O
is	O
not	O
added	O
and	O
the	O
result	O
is	O
one	O
less	O
than	O
the	O
radix	B-Algorithm
complement	I-Algorithm
of	O
the	O
answer	O
,	O
or	O
the	O
diminished	B-Algorithm
radix	I-Algorithm
complement	I-Algorithm
,	O
which	O
does	O
not	O
require	O
an	O
addition	O
to	O
obtain	O
.	O
</s>
<s>
The	O
method	B-Algorithm
of	I-Algorithm
complements	I-Algorithm
was	O
used	O
in	O
many	O
mechanical	O
calculators	O
as	O
an	O
alternative	O
to	O
running	O
the	O
gears	O
backwards	O
.	O
</s>
<s>
Pascal	O
's	O
calculator	O
had	O
two	O
sets	O
of	O
result	O
digits	O
,	O
a	O
black	O
set	O
displaying	O
the	O
normal	O
result	O
and	O
a	O
red	O
set	O
displaying	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
this	O
.	O
</s>
<s>
Then	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
the	O
minuend	O
was	O
entered	O
.	O
</s>
<s>
without	O
having	O
to	O
mentally	O
determine	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
the	O
minuend	O
)	O
.	O
</s>
<s>
In	O
displaying	O
that	O
data	O
in	O
the	O
complement	O
window	O
(	O
red	O
set	O
)	O
,	O
the	O
operator	O
could	O
see	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
the	O
minuend	O
,	O
that	O
is	O
the	O
minuend	O
.	O
</s>
<s>
The	O
slat	O
was	O
then	O
moved	O
to	O
expose	O
the	O
black	O
digits	O
(	O
which	O
now	O
displayed	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
the	O
minuend	O
)	O
and	O
the	O
subtrahend	O
was	O
added	O
by	O
dialing	O
it	O
in	O
.	O
</s>
<s>
The	O
Comptometer	O
had	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
digits	O
printed	O
in	O
smaller	O
type	O
along	O
with	O
the	O
normal	O
digits	O
on	O
each	O
key	O
.	O
</s>
<s>
Since	O
subtracting	O
1	O
before	O
complementing	O
is	O
equivalent	O
to	O
adding	O
1	O
afterwards	O
,	O
the	O
operator	O
would	O
thus	O
effectively	O
add	O
the	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
of	O
the	O
subtrahend	O
.	O
</s>
<s>
The	O
Curta	O
calculator	O
used	O
the	O
method	B-Algorithm
of	I-Algorithm
complements	I-Algorithm
for	O
subtraction	O
,	O
and	O
managed	O
to	O
hide	O
this	O
from	O
the	O
user	O
.	O
</s>
<s>
This	O
alternate	O
row	O
contained	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
of	O
the	O
digits	O
.	O
</s>
<s>
The	O
shifted	O
drum	O
also	O
engaged	O
one	O
extra	O
cam	O
which	O
added	O
1	O
to	O
the	O
result	O
(	O
as	O
required	O
for	O
the	O
method	B-Algorithm
of	I-Algorithm
complements	I-Algorithm
)	O
.	O
</s>
<s>
The	O
always	O
present	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
"	O
overflow	O
1	O
"	O
which	O
carried	O
out	O
beyond	O
the	O
most	O
significant	O
digit	O
of	O
the	O
results	O
register	O
was	O
,	O
in	O
effect	O
,	O
discarded	O
.	O
</s>
<s>
Use	O
of	O
the	O
method	B-Algorithm
of	I-Algorithm
complements	I-Algorithm
is	O
ubiquitous	O
in	O
digital	O
computers	O
,	O
regardless	O
of	O
the	O
representation	O
used	O
for	O
signed	O
numbers	O
.	O
</s>
<s>
If	O
two	B-General_Concept
's	I-General_Concept
complement	I-General_Concept
representation	O
is	O
used	O
,	O
subtraction	O
requires	O
only	O
inverting	O
the	O
bits	O
of	O
the	O
subtrahend	O
and	O
setting	O
a	O
carry	O
into	O
the	O
rightmost	O
bit	O
.	O
</s>
<s>
The	O
method	B-Algorithm
of	I-Algorithm
complements	I-Algorithm
was	O
used	O
to	O
correct	O
errors	O
when	O
accounting	O
books	O
were	O
written	O
by	O
hand	O
.	O
</s>
<s>
To	O
remove	O
an	O
entry	O
from	O
a	O
column	O
of	O
numbers	O
,	O
the	O
accountant	O
could	O
add	O
a	O
new	O
entry	O
with	O
the	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
of	O
the	O
number	O
to	O
subtract	O
.	O
</s>
<s>
For	O
decimal	B-Application
currencies	O
that	O
would	O
be	O
10	O
,	O
100	O
,	O
1	O
,	O
000	O
,	O
etc.	O
,	O
e.g.	O
</s>
<s>
In	O
grade	O
schools	O
,	O
students	O
are	O
sometimes	O
taught	O
the	O
method	B-Algorithm
of	I-Algorithm
complements	I-Algorithm
as	O
a	O
shortcut	O
useful	O
in	O
mental	O
arithmetic	O
.	O
</s>
<s>
Subtraction	O
is	O
done	O
by	O
adding	O
the	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
of	O
the	O
subtrahend	O
,	O
which	O
is	O
the	O
nines	B-Algorithm
 '	I-Algorithm
complement	I-Algorithm
plus	O
1	O
.	O
</s>
<s>
The	O
result	O
of	O
this	O
addition	O
is	O
used	O
when	O
it	O
is	O
clear	O
that	O
the	O
difference	O
will	O
be	O
positive	O
,	O
otherwise	O
the	O
ten	B-Algorithm
's	I-Algorithm
complement	I-Algorithm
of	O
the	O
addition	O
's	O
result	O
is	O
used	O
with	O
it	O
marked	O
as	O
negative	O
.	O
</s>
