NegaFibonacci coding

NegaFibonacci coding
Numeral systems by culture
Hindu-Arabic numerals
Western Arabic (Hindu numerals)
Eastern Arabic
Indian family
Tamil
Burmese
Khmer
Lao
Mongolian
Thai
East Asian numerals
Chinese
Japanese
Suzhou
Korean
Vietnamese
Counting rods
Alphabetic numerals
Abjad
Armenian
Āryabhaṭa
Cyrillic
Ge'ez
Greek (Ionian)
Hebrew
Other systems
Aegean
Attic
Babylonian
Brahmi
Egyptian
Etruscan
Inuit
Kharosthi
Mayan
Quipu
Roman
Sumerian
Urnfield
List of numeral system topics
Positional systems by base
Decimal (10)
2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 20, 24, 30, 36, 60, 64
List of numeral systems
v · d · e

In mathematics, negaFibonacci coding is a universal code which encodes integers into binary code words. It is similar to Fibonacci coding, except that it allows both positive and negative integers to be represented. All codes end with "11" and have no "11" before the end. The code for the integers from -11 to 11 is given below.

xx  negaFibonacci representation            negaFibonacci code
-11  101000                                 0001011
-10  101001                                 1001011
-9   100010                                 0100011
-8   100000                                 0000011
-7   100001                                 1000011
-6   100100                                 0010011
-5   100101                                 1010011
-4   1010                                   01011
-3   1000                                   00011
-2   1001                                   10011
-1   10                                     011
0    0                                      01
1    1                                      11
2    100                                    0011
3    101                                    1011
4    10010                                  010011
5    10000                                  000011
6    10001                                  100011
7    10100                                  001011
8    10101                                  101011
9    1001010                                01010011
10   1001000                                00010011
11   1001001                                10010011

The Fibonacci code is closely related to negaFibonacci representation, a positional numeral system sometimes used by mathematicians. The negaFibonacci code for a particular integer is exactly that of the integer's negaFibonacci representation, except with the order of its digits reversed and an additional "1" appended to the end. The negaFibonacci code for all negative numbers has an odd number of digits, while those of all positive numbers have an even number of digits.

To encode an integer X:

  1. Calculate the largest (or smallest) encodeable number with N bits by summing the odd (or even) negafibonacci numbers from 1 to N.
  2. 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.
  3. 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.
  4. Put a one in the N+1th bit to finish.

To decode a token in the code, remove the last "1", assign the remaining bits the values 1,-1,2,-3,5,-8,13... (the negafibonacci numbers), and add the "1" bits.

See also


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Negafibonacci — DefinitionIn mathematics, negaFibonacci numbers are the negatively indexed elements of the Fibonacci sequence.The negaFibonacci numbers are defined inductively by the recurrence relation: *F 1 = 1, *F 2 = 1, *Fn = F(n+2)−F(n+1).They may be… …   Wikipedia

  • List of mathematics articles (N) — NOTOC N N body problem N category N category number N connected space N dimensional sequential move puzzles N dimensional space N huge cardinal N jet N Mahlo cardinal N monoid N player game N set N skeleton N sphere N! conjecture Nabla symbol… …   Wikipedia

  • Fibonacci — Infobox Scientist box width = 300px name = Leonardo of Pisa (Fibonacci) image width = 150px caption = Leonardo of Pisa, Fibonacci birth date = c. 1170 birth place = Pisa, Italy death date = c. 1250 death place = Pisa, Italy residence = Italy… …   Wikipedia

  • Fibonacci number — A tiling with squares whose sides are successive Fibonacci numbers in length …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”