Professional Documents
Culture Documents
3) Fibonacci Coding
3) Fibonacci Coding
Fibonacci Coding
• It can be shown that such a coding is unique, and the only occurrence
of "11" in any code word is at the end.
Algorithm:
To encode an integer N
• Find the largest Fibonacci number equal to or less than N; subtract
this number from N, keeping track of the remainder.
• If the number subtracted was the ith Fibonacci number F(i), put a 1 in
place i−2 in the code word (counting the left most digit as place 0).
• Repeat the previous steps, substituting the remainder for N, until a
remainder of 0 is reached.
• Place an additional 1 after the rightmost digit in the code word.
• The extra 1 is appended to indicate the end of the code.
Examples:
F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
1 1 2 3 5 8 13 21 34 55 89 144
N = 33 N=2
100120140161 0111
N = 13 N=1
00000151101
N = 14 N = 126
100000151 0012000017 019 1
Fibonacci coding of first 14 integers
Decoding:
• To decode a code word, remove the final "1", assign the remaining
the values 1,2,3,5,8,13... (the Fibonacci numbers) to the bits in the
code word, and sum the values of the "1" bits.
• It can be shown that such a coding is unique, and the only occurrence
of “11” in any code word is only at the end.
Example:
• 0101010011
F1 F2 F3 F4 F5 F6 F7 F8 F9 F10 F11 F12
1 1 2 3 5 8 13 21 34 55 89 144
Exercise:
• 010101011 = 54
• 1010100011 =
• 101010010011
• 0101010101011