ArticleslgStudy

science

Elias gamma coding

Elias gamma coding is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Elias gamma coding rather than just read about it. In short: Elias γ code or 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.

Key takeaways

  • Elias gamma coding belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Elias gamma coding to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Elias gamma coding from memory before moving on to harder problems.

Reference excerpt

Elias γ code or 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.

Encoding To code a number x ≥ 1:

Let N=⌊log2x⌋ be the highest power of 2 it contains, so 2N ≤ x < 2N+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⌊log2(x)⌋+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 2N, 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 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 be 00000101, while the γ-encoding variable-bit version would be 00 1 01, needing 3 bits fewer. On the contrary, bigger values, like 254 stored in fixed 8-bit size, would be 11111110 while the γ-encoding variable-bit version would be 0000000 1 1111110, needing 7 extra bits. 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, 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: {x↦2x+1when x≥0x↦−2xwhen x<0 Exponential-Golomb coding generalizes the gamma code to integers with a "flatter" power-law distribution, just as Golomb 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.

Code length The code lengths for Elias gamma coding are:

1, 3, 3, 5, 5, 5, 5, 7, 7, 7, 7, 7, 7, 7, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 11, … (sequence A129972 in the OEIS).

See also Elias delta (δ) coding – Universal code encoding positive integers Elias omega (ω) coding – Universal code encoding positive integers Posit (number format) – Variant of floating-point numbers in computersPages displaying short descriptions of redirect targets

References

Further reading Sayood, Khalid (2003). "Levenstein and Elias Gamma Codes". Lossless Compression Handbook. Elsevier. ISBN 978-0-12-620861-0.

Worked examples

Example 1 — a first encounter with Elias gamma coding

Start with the simplest possible case. Write down what Elias gamma coding claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Elias gamma coding before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Elias gamma coding ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Elias gamma coding

In research
Elias gamma coding appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Elias gamma coding in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Elias gamma coding is common in secondary-school and first-year university syllabi. It links to neighbouring topics Data compression, Entropy coding, Numeral systems, so understanding it makes those chapters shorter.
In everyday life
Look for Elias gamma coding outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Elias gamma coding” →

How to study Elias gamma coding in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Elias gamma coding means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Elias gamma coding out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Elias gamma coding in simple terms?

Elias γ code or 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.

Why does Elias gamma coding matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Elias gamma coding?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Elias gamma coding.

Tags

  • Data compression
  • Entropy coding
  • Numeral systems

Keep exploring