CalcWorldHub
Free online calculator · no signup

Canonical binary prefix-code assignment calculator

Construct reproducible canonical prefix codewords from a supplied length table, keeping the original symbol ordering.

4,000 tools
Canonical binary prefix-code assignment calculator — Codeword lengths in symbol order (bits) and calculation method
Canonical binary prefix-code assignment calculator: inputs and calculation method.

How to use this calculator

Construct reproducible canonical prefix codewords from a supplied length table, keeping the original symbol ordering.

  1. Enter Codeword lengths in symbol order (bits). Match the units shown beside each field and review the result together with the assumptions below.
  2. Read the worked example below to check the expected input format and result.
  3. Compare another scenario by changing one input at a time. Use Reset to return to the starting values.
Calculation guide

Canonical binary prefix-code assignment explained

This guide follows canonical binary prefix-code assignment calculator from its stated formula through a worked example, then identifies the assumptions that bound the result.

Kraft occupancy0.75fraction
Kraft occupancy: 0.75 fraction in the worked scenario.

A numerical walkthrough

Codeword lengths in symbol order (bits) = 2,3,3,3,3.

  • Kraft occupancy: 0.75 fraction
  • Unused binary prefix capacity: 0.25 fraction
  • Symbol 1 code integer (2 bits): 0 unsigned integer
  • Symbol 2 code integer (3 bits): 2 unsigned integer
  • Symbol 3 code integer (3 bits): 3 unsigned integer
  • Symbol 4 code integer (3 bits): 4 unsigned integer
  • Symbol 5 code integer (3 bits): 5 unsigned integer

Lengths 2,3,3,3,3 leave unused prefix capacity. Their canonical integers must be written with the stated bit widths, retaining leading zeros.

The model behind the numbers

K=Σ_i 2^(−ℓ_i)≤1; after sorting by length then symbol index, c_NEXT=(c_PREV+1)2^(ℓ_NEXT−ℓ_PREV).

Check the Kraft condition before assigning codes. Sort only for assignment, then return each code to its input symbol position; this permits a decoder to reproduce codes from lengths alone.

What to enter

lengths — Codeword lengths in symbol order (bits)
One positive length per input symbol; equal-length ties preserve symbol order. Use comma-separated values in the stated order.

Interpreting the result

One to twelve binary symbols, lengths one through twenty-four bits. This does not optimize lengths, encode text or define a container format.

Reading the outputs

Kraft occupancy reports prefix-space usage. Each remaining metric is one complete symbol code as an exact integer with its required bit width in the label.

Assumptions and limits

Assume positive integer codeword lengths for a binary prefix code. Kraft’s sum must be at most 1; canonical assignment orders by length and then by the supplied symbol order. This assigns codes from lengths and does not optimize lengths from symbol frequencies.

Frequently asked questions

Do leading zero bits matter?

Yes; integer one at length three means 001, not the one-bit code 1.

Does Kraft sum below one mean invalid lengths?

No; it means a valid incomplete prefix tree with unused coding space.

Will equal-frequency Huffman trees produce the same codes?

Not necessarily; canonical assignment fixes codes once lengths and symbol ordering are supplied.

How do I use the Canonical binary prefix-code assignment calculator?

Enter Codeword lengths in symbol order (bits). Match the units shown beside each field and review the result together with the assumptions below.

What is a worked example of Canonical binary prefix-code assignment?

Codeword lengths in symbol order (bits) = 2,3,3,3,3. Kraft occupancy: 0.75 fraction Unused binary prefix capacity: 0.25 fraction Symbol 1 code integer (2 bits): 0 unsigned integer Symbol 2 code integer (3 bits): 2 unsigned integer Symbol 3 code integer (3 bits): 3 unsigned integer Symbol 4 code integer (3 bits): 4 unsigned integer Symbol 5 code integer (3 bits): 5 unsigned integer Lengths 2,3,3,3,3 leave unused prefix capacity. Their canonical integers must be written with the stated bit widths, retaining leading zeros.