Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 8

Fibonacci Coding

Fibonacci Coding

• Fibonacci coding is a universal code which encodes positive integers


into binary code words where each code word ends with 11 and 11
occurs only once in the code.

• 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.

• For any N, if d(0), d(1), … ,d(k) represents the code then,

N = ∑ d(i) Fi+2 where d(k) = d(k-1) = 1

• 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

You might also like