Unary coding: Difference between revisions

Content deleted Content added
m clean up, typo(s) fixed: ie → i.e. (2)
Line 51:
 
==Standard run-length unary codes==
All binary data is defined by the ability to represent unary numbers in alternating run-lengths of 1s and 0s. This conforms to the standard definition of unary iei.e. N digits of the same number 1 or 0. All run-lengths by definition have at least one digit and thus represent ''strictly positive integers''.
{| class="wikitable"
! n !! RL code !! Next code
Line 168:
| colspan="4" | ...
|}
 
==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'.
Line 206 ⟶ 207:
| colspan="3" |
|}
Canonical codes can [http://www.cs.ucf.edu/courses/cap5015/Huff.pdf require less processing time to decode] when they are processed as numbers not a string. If the number of codes required per symbol length is different to 1, iei.e. there are more non-unary codes of some length required, those would be achieved by increasing/decreasing the values numerically without reducing the length in that case.
 
==Generalized unary coding==
A generalized version of unary coding was presented by [[Subhash Kak]] to represent numbers much more efficiently than standard unary coding.<ref name="Kak_2015"/> Here's an example of generalized unary coding for integers from 0 through 15 that requires only 7 bits (where three bits are arbitrarily chosen in place of a single one in standard unary to show the number). Note that the representation is cyclic where one uses markers to represent higher integers in higher cycles.