*** Welcome to piglix ***

Elias gamma coding


Elias gamma code is a universal code encoding positive integers developed by Peter Elias. It is used most commonly when coding integers whose upper-bound cannot be determined beforehand.

To code a number x≥1:

An equivalent way to express the same process:

To represent a number , Elias gamma uses bits.

The code begins (the implied probability distribution for the code is added for clarity):

To decode an Elias gamma-coded integer:

Gamma coding is used in applications where the largest encoded value is not known ahead of time, or to compress data in which small values are much more frequent than large values.

Gamma coding is a building block in the Elias delta code.

Gamma coding does not code zero or negative integers. One way of handling zero is to add 1 before coding and then subtract 1 after decoding. Another way is to prefix each nonzero code with a 1 and then code zero as a single 0.


...
Wikipedia

...