Unary coding: Difference between revisions

Content deleted Content added
Symmetric unary codes: grammar and simplify.
Symmetric unary codes: simplify symmetric
Line 144:
 
==Symmetric unary codes==
The following set ofsymmetric unary codes arecan symmetricbe read and instantaneously decoded in either direction:
{| class="wikitable" style="text-align: center;"
! n (strictly positive) !! Unary code
!Alternative
!n (non-negative)
!n (strictly positive)
|-
| 1 || 1
|0
|0
|1
|-
| 2 || 00
|11
|1
|2
|-
| 3 || 010
|101
|2
|3
|-
| 4 || 0110
|1001
|3
|4
|-
| 5 || 01110
|10001
|4
|5
|-
| 6 || 011110
|100001
|5
|6
|-
| 7 || 0111110
|1000001
|6
|7
|-
| 8 || 01111110
|10000001
|7
|8
|-
| 9 || 011111110
|100000001
|8
|9
|-
| 10 || 0111111110
|1000000001
|9
|10
|-
| colspan="4" | ...
|}
These symmetric codes can be read and instantaneously decoded in either direction.
 
== Canonical unary codes ==
For unary values where the maximum is known, one can use canonical unary codes that are of a somewhat numerical nature and different from character based codes. It involves starting with numerical '0' or '-1' ( <math>\operatorname2^{n} - 1\,</math>) and the maximum number of digits then for each step reducing the number of digits by one and increasing/decreasing the result by numerical '1'.
{| class="wikitable"