midi variable length quantity converter
MIDI VLQ Converter guide
Inspect the variable-length integer representation used by Standard MIDI Files for delta times and certain lengths. Choose decimal-to-VLQ or VLQ-to-decimal, then read the decoded number and shortest byte sequence.
Play the instrument ↑- Input reference
- An SMF VLQ stores seven value bits per byte, most-significant group first.
Formula and input units
An SMF VLQ stores seven value bits per byte, most-significant group first. Bit 7 is set on every continuation byte and clear on the final byte. The supported unsigned range is 0 through 268,435,455, hexadecimal 0FFFFFFF, using at most four bytes.
Worked examples
Decimal 128 encodes as 81 00. The first byte contributes seven-bit value 1 and indicates another byte, while the final byte contributes 0. Combining the groups gives 1 × 128 + 0.
Decimal 127 encodes as 7F, decimal 16,384 as 81 80 00, and the maximum 268,435,455 as FF FF FF 7F. Zero is 00. These boundary cases check the transition between one, two, three and four bytes.
Using the result
For encoding, enter a whole decimal value within the allowed range. For decoding, select VLQ to decimal and enter one to four two-digit hexadecimal bytes separated by spaces. The unused opposite-direction field can retain its default value.
Read a complete VLQ from the surrounding MIDI file structure. A delta time precedes an event, and some meta or system-exclusive event lengths also use VLQ. A byte with its high bit clear terminates this integer; subsequent bytes belong to the next field.
Inspect byte boundaries without losing field alignment
The value 16,383 uses FF 7F and 16,384 uses 81 80 00. At the next boundary, 2,097,151 uses FF FF 7F and 2,097,152 uses 81 80 80 00. Testing both sides of these boundaries checks how the seven-bit groups expand. A normal fixed-width big-endian integer would show different bytes because its groups carry eight value bits instead.
Decode 81 00 by removing the continuation flags to obtain groups 01 and 00. Multiply the accumulated value by 128 before adding each following group. Starting from zero gives 1 after the first group and 128 after the second. The same accumulation method handles all one-to-four-byte values without interpreting the first byte as a signed number.
A malformed sequence can consume bytes belonging to another field if a parser keeps searching for an ending byte. The four-byte limit and continuation checks here provide a narrow validation of the supplied integer. They do not validate track chunk lengths, event ordering, running-status rules or whether an event length matches its actual payload. Those checks belong to the surrounding file parser.
For a timing example, a delta value of 128 ticks with 480 ticks per quarter corresponds to 128/480 of a quarter note. At a constant 120 BPM this is about 133.333333 ms. The VLQ representation remains 81 00 even if tempo changes. Tempo and file division give the timing interpretation, while the integer encoding itself only stores the unsigned count.
Whitespace separates the hexadecimal bytes in decode mode. Enter 81 00 as two bytes, rather than the concatenated text 8100 or a decimal-looking number. Both 0A and 0a are accepted for a byte because hexadecimal case has no numeric meaning. The form reports uppercase normalized bytes so outputs can be compared consistently with a MIDI monitor, documentation table or binary file inspection.
Assumptions and limits
The decoder checks byte syntax, maximum length and continuation-bit placement. It accepts a structurally valid nonminimal representation such as 80 00, decodes it as zero and reports the shortest form 00. The calculator reports the normalized form for comparison.
VLQ is distinct from a MIDI channel-message data byte, running status and a general signed variable-length encoding. This page converts a single integer. It neither parses a complete track nor converts ticks to elapsed time without tempo and division information.
Music theory tools → · MIDI Tick Calculator → · MIDI Association Standard MIDI Files →
Answers before you play
Common questions
Why is 80 rejected as a complete value?
Its continuation bit is set, so another byte is required. A complete VLQ ends with a byte whose high bit is clear.
Are byte groups little-endian?
SMF VLQ stores the most-significant seven-bit group first. It differs from several other varint formats.
Can I encode negative delta times?
The Standard MIDI File VLQ represented here is unsigned. Use a value from zero through 0FFFFFFF hexadecimal.
Does a delta-time VLQ contain the tempo?
It stores a count of delta ticks. Converting that count to time requires the MIDI file division and the tempo map for PPQ-based files. SMPTE-based division uses its stated timing convention. The same VLQ bytes can therefore represent different elapsed times.