Movatterモバイル変換


[0]ホーム

URL:


Jump to content
WikipediaThe Free Encyclopedia
Search

Elias gamma coding

From Wikipedia, the free encyclopedia
Universal encoding scheme for positive integers

Eliasγ{\displaystyle \gamma } code orElias gamma code is auniversal code encoding positive integers developed byPeter Elias.[1]: 197, 199  It is used most commonly when coding integers whose upper bound cannot be determined beforehand.

Encoding

[edit]

To code anumberx ≥ 1:

  1. LetN=log2x{\displaystyle N=\lfloor \log _{2}x\rfloor } be the highest power of 2 it contains, so 2Nx < 2N+1.
  2. Write outN{\displaystyle N} zero bits, then
  3. Append thebinary form ofx{\displaystyle x}, an(N+1){\displaystyle (N+1)}-bit binary number.

An equivalent way to express the same process:

  1. EncodeN{\displaystyle N} inunary; that is, asN{\displaystyle N} zeroes followed by a one.
  2. Append the remainingN{\displaystyle N} binary digits ofx{\displaystyle x} to this representation ofN{\displaystyle N}.

To represent a numberx{\displaystyle x}, Elias gamma (γ) uses2log2(x)+1{\displaystyle 2\lfloor \log _{2}(x)\rfloor +1} bits.[1]: 199 

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

NumberBinaryγ encodingImplied probability
1 = 20 + 0111/2
2 = 21 +01 00 1 01/8
3 = 21 +11 10 1 11/8
4 = 22 +01 0000 1 001/32
5 = 22 +11 0100 1 011/32
6 = 22 +21 1000 1 101/32
7 = 22 +31 1100 1 111/32
8 = 23 +01 000000 1 0001/128
9 = 23 +11 001000 1 0011/128
10 = 23 +21 010000 1 0101/128
11 = 23 +31 011000 1 0111/128
12 = 23 +41 100000 1 1001/128
13 = 23 +51 101000 1 1011/128
14 = 23 +61 110000 1 1101/128
15 = 23 +71 111000 1 1111/128
16 = 24 +01 00000000 1 00001/512
17 = 24 + 11 00010000 1 00011/512

Decoding

[edit]

To decode an Elias gamma-coded integer:

  1. Read and count 0s from the stream until you reach the first 1. Call this count of zeroesN.
  2. Considering the one that was reached to be the first digit of the integer, with a value of 2N, read the remainingN digits of the integer.

Uses

[edit]

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

Gamma coding can be more size efficient in those situations. For example, note that, in the table above, if a fixed 8-bit size is chosen to store a small number like the number 5, the resulting binary would be00000101, while the γ-encoding variable-bit version would be00 1 01, needing 3 bits less. On the contrary, bigger values, like 254 stored in fixed 8-bit size, would be11111110 while the γ-encoding variable-bit version would be0000000 1 1111110, needing 7 extra bits.

Gamma coding is a building block in theElias delta code.

Generalizations

[edit]
See also:Variable-length quantity § Zigzag encoding

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 abijection, 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 invertedsign bit:
{x2x+1when x0x2xwhen x<0{\displaystyle {\begin{cases}x\mapsto 2x+1&\mathrm {when~} x\geq 0\\x\mapsto -2x&\mathrm {when~} x<0\\\end{cases}}}

Exponential-Golomb coding generalizes the gamma code to integers with a "flatter" power-law distribution, just asGolomb coding 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

[edit]

References

[edit]
  1. ^abElias, Peter (March 1975). "Universal codeword sets and representations of the integers".IEEE Transactions on Information Theory.21 (2):194–203.doi:10.1109/tit.1975.1055349.

Further reading

[edit]
Lossless
type
Entropy
Dictionary
Other
Hybrid
Lossy
type
Transform
Predictive
Audio
Concepts
Codec
parts
Image
Concepts
Methods
Video
Concepts
Codec
parts
Theory
Community
People
Retrieved from "https://en.wikipedia.org/w/index.php?title=Elias_gamma_coding&oldid=1285268729"
Categories:
Hidden categories:

[8]ページ先頭

©2009-2026 Movatter.jp