Negafibonacci coding: Difference between revisions

Content deleted Content added
No edit summary
m Typo fixing, typos fixed: , → , using AWB
Line 34:
To encode an integer ''X'':
# Calculate the largest (or smallest) encodeable number with ''N'' bits by summing the odd (or even) [[negafibonacci]] numbers from 1 to ''N''.
# When it is determined that ''N'' bits is just enough to contain ''X'', subtract the ''Nth'' negaFibonacci number from ''X'' , keeping track of the remainder, and put a one in the ''Nth'' bit of the output.
# Working downward from the ''Nth'' bit to the first one, compare each of the corresponding negaFibonacci numbers to the remainder. Subtract it from the remainder if the absolute value of the difference is less, AND if the next higher bit does not already have a one in it. A one is placed in the appropriate bit if the subtraction is made, or a zero if not.
# Put a one in the ''N+1th'' bit to finish.