Universal Integer Codes
Turn one whole number into the self-delimiting bit codes that compressors use — Elias gamma and delta, Fibonacci, Golomb–Rice and Golomb — or read a code word back to its value.
A universal code maps the whole numbers to bit strings that need no separate length: the reader can find the end of each code word. Elias gamma writes the bit length of the number as that many zeros and then the number itself, so it takes 2 floor(log2 n) + 1 bits. Elias delta codes the bit length with a gamma code first, which pays off for large values. Fibonacci coding writes the number in the Zeckendorf representation — a sum of non-consecutive Fibonacci numbers — least significant digit first, then appends a 1, so every code word ends in 11 and no earlier 11 appears. Golomb and Golomb–Rice codes split the value into a quotient and a remainder: the quotient in unary as ones and a closing zero, the remainder in truncated binary, which uses b bits when r < 2b+1 − m and b+1 otherwise, with b = floor(log2 m); Rice is the special case m = 2k. Code words longer than 4,096 bits are refused so the page stays responsive: raise the Rice parameter or the Golomb divisor. Everything is computed in your browser; nothing is sent or stored.