Truncated Binary Encoding - Example With n = 7

Example With n = 7

Here is a more extreme case: with n = 7 the next power of 2 is 8 (we will then use 3 bits or 2 bits if the high bit is discarded) and u = 1:

Input
value
Offset Offset
value
Standard
Binary
Truncated
Binary
0 0 0 000 00 
1 1 2 010 010
2 1 3 011 011
3 1 4 100 100
4 1 5 101 101
5 1 6 110 110
6 1 7 111 111

This last example demonstrates that a leading zero bit does not always indicate a short code; if u < 2k−1, some long codes will begin with a zero bit.

If n is a power of two, then the encoding may be done with either of two different values of k. Both produce equivalent outputs; one just has u = 2k and encodes all values as "short" k-bit codes, while the other has u = 0 and encodes everything with "long" k+1-bit codes.

Read more about this topic:  Truncated Binary Encoding