<s>
In	O
mathematics	O
,	O
negafibonacci	B-Algorithm
coding	I-Algorithm
is	O
a	O
universal	B-Algorithm
code	I-Algorithm
which	O
encodes	O
nonzero	O
integers	O
into	O
binary	O
code	O
words	O
.	O
</s>
<s>
It	O
is	O
similar	O
to	O
Fibonacci	B-Algorithm
coding	I-Algorithm
,	O
except	O
that	O
it	O
allows	O
both	O
positive	O
and	O
negative	O
integers	O
to	O
be	O
represented	O
.	O
</s>
<s>
Calculate	O
the	O
largest	O
(	O
or	O
smallest	O
)	O
encodeable	O
number	O
with	O
N	O
bits	O
by	O
summing	O
the	O
odd	O
(	O
or	O
even	O
)	O
negafibonacci	B-Algorithm
numbers	O
from	O
1	O
to	O
N	O
.	O
</s>
<s>
When	O
it	O
is	O
determined	O
that	O
N	O
bits	O
is	O
just	O
enough	O
to	O
contain	O
X	O
,	O
subtract	O
the	O
Nth	O
negafibonacci	B-Algorithm
number	O
from	O
X	O
,	O
keeping	O
track	O
of	O
the	O
remainder	O
,	O
and	O
put	O
a	O
one	O
in	O
the	O
Nth	O
bit	O
of	O
the	O
output	O
.	O
</s>
<s>
Working	O
downward	O
from	O
the	O
Nth	O
bit	O
to	O
the	O
first	O
one	O
,	O
compare	O
each	O
of	O
the	O
corresponding	O
negafibonacci	B-Algorithm
numbers	O
to	O
the	O
remainder	O
.	O
</s>
<s>
To	O
decode	O
a	O
token	O
in	O
the	O
code	O
,	O
remove	O
the	O
last	O
"	O
1	O
"	O
,	O
assign	O
the	O
remaining	O
bits	O
the	O
values	O
1	O
,	O
−1	O
,	O
2	O
,	O
−3	O
,	O
5	O
,	O
−8	O
,	O
13	O
...	O
(	O
the	O
negafibonacci	B-Algorithm
numbers	O
)	O
,	O
and	O
add	O
the	O
"	O
1	O
"	O
bits	O
.	O
</s>
<s>
Negafibonacci	B-Algorithm
coding	I-Algorithm
is	O
closely	O
related	O
to	O
negafibonacci	B-Algorithm
representation	O
,	O
a	O
positional	O
numeral	O
system	O
sometimes	O
used	O
by	O
mathematicians	O
.	O
</s>
<s>
The	O
negafibonacci	B-Algorithm
code	O
for	O
a	O
particular	O
nonzero	O
integer	O
is	O
exactly	O
that	O
of	O
the	O
integer	O
's	O
negafibonacci	B-Algorithm
representation	O
,	O
except	O
with	O
the	O
order	O
of	O
its	O
digits	O
reversed	O
and	O
an	O
additional	O
"	O
1	O
"	O
appended	O
to	O
the	O
end	O
.	O
</s>
<s>
The	O
negafibonacci	B-Algorithm
code	O
for	O
all	O
negative	O
numbers	O
has	O
an	O
odd	O
number	O
of	O
digits	O
,	O
while	O
those	O
of	O
all	O
positive	O
numbers	O
have	O
an	O
even	O
number	O
of	O
digits	O
.	O
</s>
