Skip to content

Instantly share code, notes, and snippets.

@gocs
Created September 7, 2025 16:46
Show Gist options
  • Select an option

  • Save gocs/14dd36df8898f3dc0390deac40d1cc01 to your computer and use it in GitHub Desktop.

Select an option

Save gocs/14dd36df8898f3dc0390deac40d1cc01 to your computer and use it in GitHub Desktop.
Variable Length Quantity

Variable Length Quantity: 1bit Continuation + 7bit encoding

((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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment