Even-Rodeh code is a universal code encoding the non-negative integers developed by Shimon Even and Michael Rodeh.
Encoding
To code a non-negative integer N in Even-Rodeh coding:
- If N is not less than 4 then set the coded value to a single
0
bit. Otherwise the coded value is empty. - If N is less than 4 then prepend the coded value with 3 bits containing the value of N and stop.
- Prepend the coded value with the binary representation of N.
- Store the number of bits prepended in step 3 as the new value of N.
- Go back to step 2.
To decode an Even-Rodeh-coded integer:
- Read 3 bits and store the value into N.
- If the first bit read was
0
then stop. The decoded number is N. - If the first bit read was
1
then continue to step 2. - Examine the next bit.
- If the bit is
0
then read 1 bit and stop. The decoded number is N. - If the bit is
1
then read N bits, store the value as the new value of N, and go back to step 2.
References
Even-Rodeh coding Wikipedia(Text) CC BY-SA