Elias delta code is a universal code encoding the positive integers developed by Peter Elias. To code a number:
An equivalent way to express the same process:
The code begins:
Implied probability
1 = 2^{0} => N' = 0, N = 1 => 1 1/2
2 = 2^{1} + 0 => N' = 1, N = 2 => 0100 1/16
3 = 2^{1} + 1 => N' = 1, N = 2 => 0101 "
4 = 2^{2} + 0 => N' = 2, N = 3 => 01100 1/32
5 = 2^{2} + 1 => N' = 2, N = 3 => 01101 "
6 = 2^{2} + 2 => N' = 2, N = 3 => 01110 "
7 = 2^{2} + 3 => N' = 2, N = 3 => 01111 "
8 = 2^{3} + 0 => N' = 3, N = 4 => 00100000 1/256
9 = 2^{3} + 1 => N' = 3, N = 4 => 00100001 "
10 = 2^{3} + 2 => N' = 3, N = 4 => 00100010 "
11 = 2^{3} + 3 => N' = 3, N = 4 => 00100011 "
12 = 2^{3} + 4 => N' = 3, N = 4 => 00100100 "
13 = 2^{3} + 5 => N' = 3, N = 4 => 00100101 "
14 = 2^{3} + 6 => N' = 3, N = 4 => 00100110 "
15 = 2^{3} + 7 => N' = 3, N = 4 => 00100111 "
16 = 2^{4} + 0 => N' = 4, N = 5 => 001010000 1/512
17 = 2^{4} + 1 => N' = 4, N = 5 => 001010001 "
To decode an Elias deltacoded integer:
 Read and count zeroes from the stream until you reach the first one. Call this count of zeroes L.
 Considering the one that was reached to be the first digit of an integer, with a value of 2^{L}, read the remaining L digits of the integer. Call this integer N.
 Put a one in the first place of our final output, representing the value 2^{N1}. Read and append the following N1 digits.
Example:
001010001
1. 2 leading zeros in 001
2. read 2 more bits i.e. 00101
3. decode N = 00101 = 5
4. get N' = 5  1 = 4 remaining bits for the complete code i.e. '0001'
5. encoded number = 2^{4} + 1 = 17
This code can be generalized to zero or negative integers in the same ways described in Elias gamma coding.
<
See also
References
Full article ▸
