Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Unary encoding is based on the number of bits of magnitude that the current upgrade pass (section 3.2.8.1.5.2) is encoding. The value to encode MUST be nonzero, positive or negative, and the magnitude (absolute value) MUST NOT exceed (1 << nBits) - 1, where nBits is the number of bits of magnitude that the upgrade pass is encoding.
First, the sign is written as a single bit.
Next, a sequence of "magnitude - 1" zeros is written.
Finally, a "1" bit terminates the sequence, except if the magnitude equals (1 << nBits) - 1.
Once this value has been encoded, the encoder returns to encoding a zero run-length. If the next value is nonzero, a zero run of length zero is encoded, and the next value is unary encoded.
Consider the case where nBits = 3. In this scenario, the magnitude MUST be between 1 and 7 (inclusive). After writing the sign, the following encodings are used for the seven possible magnitudes:
1 is encoded as "1"
2 is encoded as "01"
3 is encoded as "001"
4 is encoded as "0001"
5 is encoded as "00001"
6 is encoded as "000001"
7 is encoded as "000000"
In the case where nBits = 1, only the sign would be written, because the magnitude cannot exceed 1.