Predict the pending byte

WriteBits(5,3), then WriteBits(75,7).

Write the ten meaningful bits before grouping into bytes.

1 / 5

Boundary trace

101 | 1001011 = 10110010 11.

Output b2 c0; six trailing zeros are padding.

Bytes() snapshots the partial byte without ending it. A later write continues from used=2.

2 / 5

Reverse gamma

Byte 14 = 00010100.

Count three zeros, encounter one, read three suffix bits 010.

The value evolves 1 → 2 → 5 → 10. One trailing zero remains.

3 / 5

Compare delta

10 has bit length 4.

gamma(4)=00100; suffix of 10=010.

delta(10)=00100010=22, eight bits versus gamma's seven. Delta is not shorter for every value.

4 / 5

Diagnose boundaries

A reader sees physical padding unless a higher-level rule stops it.

More than 63 gamma prefix zeros cannot represent uint64. A decoded delta length above 64 is invalid.

Independent vectors catch shared convention mistakes; round trips alone do not.

5 / 5
←/→ or click edges to navigate · ? help · N notes · F fullscreen