ForHosting KIT · Math

Fibonacci coding converter

Turn any positive integer into its Fibonacci code: 6 becomes 10011, built from the summands 1 and 5. Each code ends in 11, so a stream of codes can be split without length markers, which suits compression homework and protocol design. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
N
6
You get
Fibonacci code
10011
Bit length
5
Zeckendorf terms
1, 5

Fibonacci coding is a universal binary code that maps every positive integer to a unique bit string that always ends with two consecutive ones. The construction uses the Zeckendorf theorem: every positive integer is the sum of non-consecutive Fibonacci numbers from the sequence that begins one, two, three, five, eight, and so on. Place a one for each summand, a zero for each skipped basis term from F two upward, then append a final terminator bit so the code ends in eleven. Students of information theory, compression homework, and protocol designers who need a self-delimiting integer encoding use this converter to check examples without hand-building the Fibonacci table.

What Fibonacci coding is and why codes end in 11

Fibonacci coding belongs to the family of universal codes for positive integers: every n greater than or equal to one receives a binary word, and no codeword is a prefix of another, so a stream of codes can be parsed without length prefixes. The key mathematical fact is Zeckendorf's theorem.

Using the Fibonacci sequence written as F two equals one, F three equals two, F four equals three, F five equals five, and so on (the usual sequence with the first one-duplication removed), every positive integer has a unique representation as a sum of non-consecutive terms from that sequence. Encoding places a bit under each basis value from F two up to the largest summand that appears: the bit is one when that Fibonacci number is used and zero otherwise.

Because Zeckendorf forbids two consecutive ones in the basis bits, the highest bit used is always one and is never followed by another one inside the basis. Appending a single terminator one therefore produces a distinctive ending of two consecutive ones. That pattern is the decoder's stop signal: read bits until you see eleven, strip the final one, and recover the Zeckendorf sum.

Classic small values make the pattern concrete. One encodes as eleven, two as zero one one, three as zero zero one one, four as one zero one one, five as zero zero zero one one, and six as one zero zero one one. Larger n simply extend the Fibonacci table until the largest Fk is at most n, run the greedy selection from the top, and emit the same terminated string.

The code length grows like O of log phi of n, so even large safe integers stay short bit strings suitable for demos, test vectors, and teaching slides about prefix-free integer codes.

Information-theory homework checks

Students encode positive integers by hand with Zeckendorf tables and verify the binary Fibonacci code (always ending in 11) against a deterministic oracle.

Compression and universal-code demos

Lesson materials compare Fibonacci coding length to Elias codes on sample integers and show the terminator pattern that makes the stream prefix-free.

How do I convert a number to Fibonacci code?

Send a positive integer n (n ≥ 1).

Why does every Fibonacci code end with 11?

Zeckendorf bits never end with two consecutive ones; a terminator 1 is appended after the highest basis bit (always 1), producing the distinctive 11 stop pattern for unique decoding.

What happens if n is zero or negative?

Fibonacci coding is defined only for positive integers (n ≥ 1), and invalid requests are not billed.

What Fibonacci sequence does the encoder use?

Greedy selection yields the unique Zeckendorf expansion without consecutive terms.

What is the Fibonacci code of 12?

12 encodes as 101011. Its Zeckendorf summands are 1, 3 and 8, which add up to 12, and the final extra 1 creates the closing 11 that marks the end of the code.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/numth/fibonacci-coding

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/numth/fibonacci-coding \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"n":6}'
{
  "n": 6
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "numth.fibonacci_coding",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Input contract, response fields, and error behaviour

Example: n equals one yields the minimal code eleven with a single Zeckendorf term equal to one. Example: n equals twelve yields one zero one zero one one with summands one, three, and eight. Clients that only need the bit string can ignore the educational fields; graders and notebooks can assert both the code and the summands to catch off-by-one errors in a student's hand table. POST a JSON body with a single required field n: a positive integer greater than or equal to one. The value may arrive as a JSON number within the safe integer range or as a plain digit string that normalizes to the same range. Missing n, empty strings, non-integers, non-finite values, zero, and any negative number fail with invalid_input and are not billed. On success the response echoes n, returns fibonacci_code as the binary string that always ends with eleven, reports bit_length as the character length of that string, lists zeckendorf_terms as the ascending Fibonacci summands that add back to n, and includes a short formula string restating the construction for display next to the answer. Example: n equals six yields fibonacci_code one zero zero one one, bit_length five, and zeckendorf_terms one and five, because five plus one equals six and the basis bits from F two through F five are one, zero, zero, one before the terminator.

Where a Fibonacci coding API earns its keep

Information-theory and compression courses use Fibonacci coding as a concrete universal code beside Elias gamma and delta; a live converter lets students check homework encodings for arbitrary positive integers without building a spreadsheet of Fibonacci numbers each time. Protocol designers evaluating variable-length integer encodings can compare Fibonacci code lengths against fixed-width and LEB128-style schemes on sample ID sequences before committing to a wire format. Failed validation does not consume balance. Because every successful call is one billable item at $0.002 with analytic cost far below that floor, the capability stays cheap for batch grading scripts and edge workers.

Test vectors for Zeckendorf-based tools

Scripts that implement Fibonacci numeration or self-delimiting IDs can pin fibonacci_code and zeckendorf_terms for many n without embedding a second implementation.

What does the Fibonacci coding converter cost?

The browser tool is free. API requests use prepaid KIT balance at $0.002 per successful call; invalid input is not billed.

Read the full KIT documentation →