Encode integers through precise Golomb partitions quickly. Inspect quotients, remainders, and bit lengths with confidence. Export reports and visualize coding behavior with sample data.
This sample demonstrates how Golomb coding behaves with divisor m = 4.
| Input n | q = floor(n / 4) | r = n mod 4 | Unary Prefix | Binary Suffix | Golomb Code | Bits |
|---|---|---|---|---|---|---|
| 3 | 0 | 3 | 0 | 11 | 011 | 3 |
| 5 | 1 | 1 | 10 | 01 | 1001 | 4 |
| 10 | 2 | 2 | 110 | 10 | 11010 | 5 |
| 12 | 3 | 0 | 1110 | 00 | 111000 | 6 |
Golomb coding splits a nonnegative integer into a quotient and a remainder using a positive divisor m.
For truncated binary coding, first compute:
If r is smaller than cutoff, encode r in b - 1 bits. Otherwise, encode r + cutoff in b bits. The final Golomb code is:
Golomb(n, m) = Unary(q) + TruncatedBinary(r)
When m is a power of two, Golomb coding becomes Rice coding, and the remainder uses a fixed binary length.
Golomb coding is a lossless entropy coding method for nonnegative integers. It represents a value using a unary quotient and a binary-style remainder, often performing well for skewed distributions.
The divisor m determines how numbers are partitioned into quotient and remainder parts. Smaller m values often increase quotient length, while larger m values can shorten unary prefixes for larger inputs.
The unary prefix is built from the quotient q. It contains q one bits followed by a zero bit. This prefix shows how many full groups of size m fit inside n.
Truncated binary coding keeps the suffix efficient when m is not a power of two. It avoids wasting code space and produces shorter average suffixes than plain fixed-width binary in those cases.
Rice coding is the special case of Golomb coding where m is a power of two. In that case, the remainder uses a fixed number of binary bits, which simplifies implementation.
Yes. Sequence mode accepts comma-separated integers. The calculator encodes every value, totals the bit lengths, computes the average bits, and plots code length against each input.
Automatic estimation chooses a reasonable m from the supplied data using a simple mean-based heuristic. It helps with quick exploration when you do not already know a suitable divisor.
This version focuses on nonnegative integers. Negative values are rejected because standard basic Golomb coding is commonly defined over nonnegative inputs unless a separate mapping step is added.
Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.