Expand description
Minimal binary codes.
A minimal binary code with upper bound u > 0 (AKA truncated binary encoding) is an optimal prefix-free code for the first u natural numbers with uniform distribution.
There are several such codes, and the one implemented here is defined as follows: let s = ⌈log₂u⌉; then, given x < u, if x < 2ˢ − u then x is coded as the binary representation of x in s − 1 bits; otherwise, x is coded as the binary representation of x − u + 2ˢ in s bits.
See the codes module documentation for some elaboration on the difference between the big-endian and little-endian versions of the codes.
Traits§
- Minimal
Binary Read - Trait for reading minimal binary codes.
- Minimal
Binary Write - Trait for writing minimal binary codes.
Functions§
- len_
minimal_ binary - Returns the length of the minimal binary code for
n
with upper boundmax
.