((1xxxxxxx)*)(0xxxxxxx)
| |
|___________|_ MSB is flag for continuation
the code above is in binary
Where:
- (1xxxxxxx)* = Zero or more bytes with bit 7 set (continuation bytes)
- (0xxxxxxx) = Exactly one byte with bit 7 clear (termination byte)
Example:
| Original Value (Hex) | Variable-Length Encoding (Hex Bytes) |
|---|---|
| 00000000 | 00 |
| 00000040 | 40 |
| 0000007F | 7F |
| 00000080 | 8100 |
| 00002000 | C000 |
| 00003FFF | FF7F |
| 00004000 | 818000 |
| 00100000 | C08000 |
| 001FFFFF | FFFF7F |
| 00200000 | 81808000 |
| 08000000 | C0808000 |
| 0FFFFFFF | FFFFFF7F |