Elias-Gamma Code
The Elias-Gamma code of a positive integer x consists of ⌊log₂ x⌋ zeroes followed by the binary representation of x, and has length 2⌊log₂ x⌋ + 1.
Know these firstPrefix-Free Code
Formula#
Properties#
- Prefix-free: the number of leading zeroes determines that exactly bits (the binary number) follow.
- Cheap for small numbers (1 bit for ), logarithmic in ; entropy-optimal for .
- Elias-Delta encodes the zeroes part itself with Gamma and wins for large .
Example#
| Binary | Code | Length | |
|---|---|---|---|
| 1 | 1 | 1 | 1 |
| 2 | 10 | 010 | 3 |
| 3 | 11 | 011 | 3 |
| 4 | 100 | 00100 | 5 |
| 7 | 111 | 00111 | 5 |
| 8 | 1000 | 0001000 | 7 |
| 15 | 1111 | 0001111 | 7 |
| 16 | 10000 | 000010000 | 9 |
Sources#
- DBIS Exam WS2223 (not published) Task 1.2 (codes for 3, 4, 7, 8, 15, 16 and the length formula)
- Not lectured in WS 25/26.