Английская Википедия:Even–Rodeh coding
Материал из Онлайн справочника
Even–Rodeh code is a universal code encoding the non-negative integers developed by Shimon Even and Michael Rodeh.[1]
Encoding
To code a non-negative integer Шаблон:Var in Even–Rodeh coding:
- If Шаблон:Var is not less than 4 then set the coded value to a single
0
bit. Otherwise the coded value is empty. - If Шаблон:Var is less than 8 then prepend the coded value with 3 bits containing the value of Шаблон:Var and stop.
- Prepend the coded value with the binary representation of Шаблон:Var.
- Store the number of bits prepended in step 3 as the new value of Шаблон:Var.
- Go back to step 2.
To decode an Even–Rodeh-coded integer:
- Read 3 bits and store the value into Шаблон:Var.
- If the first bit read was
0
then stop. The decoded number is Шаблон:Var. - If the first bit read was
1
then continue to step 2.
- If the first bit read was
- Examine the next bit.
- If the bit is
0
then read 1 bit and stop. The decoded number is Шаблон:Var. - If the bit is
1
then read Шаблон:Var bits, store the value as the new value of Шаблон:Var, and go back to step 2.
- If the bit is
Examples
Number | Encoding | Implied probability |
---|---|---|
0 | 000 |
1/8 |
1 | 001 |
1/8 |
2 | 010 |
1/8 |
3 | 011 |
1/8 |
4 | 100 0 |
1/16 |
5 | 101 0 |
1/16 |
6 | 110 0 |
1/16 |
7 | 111 0 |
1/16 |
8 | 100 1000 0 |
1/256 |
9 | 100 1001 0 |
1/256 |
︙ | ||
15 | 100 1111 0 |
1/256 |
16 | 101 10000 0 |
1/512 |
︙ | ||
2761 | Шаблон:Nowrap | 1/1,048,576 |
︙ |
See also
References
- ↑ Ошибка цитирования Неверный тег
<ref>
; для сносокEvenRodeh
не указан текст