HOME

TheInfoList



OR:

Elias γ code or Elias gamma code is a universal code encoding positive integers developed by
Peter Elias Peter Elias (November 23, 1923 – December 7, 2001) was a pioneer in the field of information theory. Born in New Brunswick, New Jersey, he was a member of the Massachusetts Institute of Technology faculty from 1953 to 1991. In 1955, Elias introdu ...
. It is used most commonly when coding integers whose upper-bound cannot be determined beforehand.


Encoding

To code a
number A number is a mathematical object used to count, measure, and label. The original examples are the natural numbers 1, 2, 3, 4, and so forth. Numbers can be represented in language with number words. More universally, individual number ...
''x'' ≥ 1: # Let N = \lfloor \log_2 x \rfloor be the highest power of 2 it contains, so 2''N'' ≤ ''x'' < 2''N''+1. # Write out ''N'' zero bits, then # Append the binary form of ''x'', an ''N''+1-bit binary number. An equivalent way to express the same process: # Encode ''N'' in unary; that is, as ''N'' zeroes followed by a one. # Append the remaining ''N'' binary digits of ''x'' to this representation of ''N''. To represent a number x, Elias gamma (γ) uses 2 \lfloor \log_2(x) \rfloor + 1 bits. The code begins (the implied probability distribution for the code is added for clarity):


Decoding

To decode an Elias gamma-coded integer: #Read and count 0s from the stream until you reach the first 1. Call this count of zeroes ''N''. #Considering the one that was reached to be the first digit of the integer, with a value of 2''N'', read the remaining ''N'' digits of the integer.


Uses

Gamma coding is used in applications where the largest encoded value is not known ahead of time, or to
compress compress is a Unix shell compression program based on the LZW compression algorithm. Compared to more modern compression utilities such as gzip and bzip2, compress performs faster and with less memory usage, at the cost of a significantly lo ...
data in which small values are much more frequent than large values. Gamma coding is a building block in the Elias delta code.


Generalizations

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. One way to code all integers is to set up a
bijection In mathematics, a bijection, also known as a bijective function, one-to-one correspondence, or invertible function, is a function between the elements of two sets, where each element of one set is paired with exactly one element of the other ...
, mapping integers (0, −1, 1, −2, 2, −3, 3, ...) to (1, 2, 3, 4, 5, 6, 7, ...) before coding. In software, this is most easily done by mapping non-negative inputs to odd outputs, and negative inputs to even outputs, so the least-significant bit becomes an inverted
sign bit In computer science, the sign bit is a bit in a signed number representation that indicates the sign of a number. Although only signed numeric data types have a sign bit, it is invariably located in the most significant bit position, so the term ...
:
\begin x \mapsto 2x+1 & \mathrm x \geq 0 \\ x \mapsto -2x & \mathrm x < 0 \\ \end Exponential-Golomb coding generalizes the gamma code to integers with a "flatter" power-law distribution, just as
Golomb coding Golomb coding is a lossless data compression method using a family of data compression codes invented by Solomon W. Golomb in the 1960s. Alphabets following a geometric distribution will have a Golomb code as an optimal prefix code, making Golomb ...
generalizes the unary code. It involves dividing the number by a positive divisor, commonly a power of 2, writing the gamma code for one more than the quotient, and writing out the remainder in an ordinary binary code.


See also

* Elias delta (δ) coding * Elias omega (ω) coding * Posit (number format)


References


Further reading

* {{DEFAULTSORT:Elias Gamma Coding Numeral systems Lossless compression algorithms Articles with example C code