Unary coding

Unary coding,[nb 1] or the unary numeral system and also sometimes called thermometer code, is an entropy encoding that represents a natural number, n, with a code of length n + 1 ( or n ), usually n ones followed by a zero (if natural number is understood as non-negative integer) or with n − 1 ones followed by a zero (if natural number is understood as strictly positive integer).

Unary coding is an optimally efficient encoding for the following discrete probability distribution for

Although it is the optimal symbol-by-symbol coding for such probability distributions, Golomb coding achieves better compression capability for the geometric distribution because it does not consider input symbols independently, but rather implicitly groups the inputs.

For the same reason, arithmetic encoding performs better for general probability distributions, as in the last case above.

[1][2] The nucleus in the brain of the songbirds that plays a part in both the learning and the production of bird song is the HVC (high vocal center).

The command signals for different notes in the birdsong emanate from different points in the HVC.

All binary data is defined by the ability to represent unary numbers in alternating run-lengths of 1s and 0s.

All run-lengths by definition have at least one digit and thus represent strictly positive integers.