Search for a tool
Elias Gamma Encoding

Tool to convert numbers according to the Elias Gamma code, denoted γ, generally used in data compression to store data of arbitrary size.

Results

Elias Gamma Encoding -

Tag(s) : Compression, Notation System

Share dCode and you

dCode is free and its tools are a valuable help in games, maths, geocaching, puzzles and problems to solve every day!
A suggestion ? a feedback ? a bug ? an idea ? Write to dCode!

Please, check our community Discord for help requests!

Thanks to your feedback and relevant comments, dCode has developped the best Elias Gamma Encoding tool, so feel free to write! Thank you !

# Elias Gamma Encoding

## Number to Elias' Gamma Encoder

 Unary writing 000...1 111...0

Tool to convert numbers according to the Elias Gamma code, denoted γ, generally used in data compression to store data of arbitrary size.

### How to encode using Elias Gamma encoding?

Elias's gamma encoding is a universal code with a prefix. The prefix indicates the length of the binary string that follows it. It is therefore possible to encode any binary integer number.

To code a decimal number $N$, take its binary representation $N_{(2)}$ and calculate $L = \lfloor \log_2 N \rfloor$ which is equivalent to its number of bits minus 1.

Example: To encode $N = 5$ which has for binary representation $N_{(2)} = 101$ (3 bits), calculate the integer part of $\log_2 5 \approx 2.32$ i.e. $L = 2$ (i.e. 1 less than the number of bits).

Encode in unary $L$ and concatenate the binary representation without the most significant bit (the first 1) to obtain the Elias Gamma code $\gamma$ that corresponds to $N$

### How to recognize a Gamma encoding?

Binary numbers have always an odd-length.

Coded values always start with a long string of 0 (or 1)

Elias Gamma encoding is generally linked to data compression algorithms.

### What are the variants of the Gamma encoding?

The unary code can be coded with 0 followed by a separator 1 or else with 1 followed by the separator 0.

Example: 5 can be coded as 000001 or 111110.

### When Gamma coding have been invented ?

Peter Elias described it in an article titled Universal codeword sets and representations of the integers in 1975.

## Source code

dCode retains ownership of the online 'Elias Gamma Encoding' tool source code. Except explicit open source licence (indicated CC / Creative Commons / free), any algorithm, applet or snippet (converter, solver, encryption / decryption, encoding / decoding, ciphering / deciphering, translator), or any function (convert, solve, decrypt / encrypt, decipher / cipher, decode / encode, translate) written in any informatic language (PHP, Java, C#, Python, Javascript, Matlab, etc.) no data, script or API access will be for free, same for Elias Gamma Encoding download for offline use on PC, tablet, iPhone or Android !

## Need Help ?

Please, check our community Discord for help requests!