Decode a variable-length quantityManchester encode a data streamCircular shift an arbitrary byte-array bitwiseDisplay a MIDI TrackOutput MSB-set aligned, delimited ASCIIBit Manipulator/ReaderBinary Countdown LengthThese are the Frequencies, KennethGolf a bit-reversal tableDecode a 7-segment displayCorrupting A Binary File By Interpreting It As Text
Print only the last three columns from file
ATPL - Principles of Flight - Question regarding propeller pitch
Traveling from Germany to other countries by train?
Who is the god Ao?
Why do private jets such as Gulfstream fly higher than other civilian jets?
Responding to Plague Engineer
ESTA declined to the US
Is it double speak?
How would a family travel from Indiana to Texas in 1911?
Why can I log in to my Facebook account with a misspelled email/password?
Is there a drawback to Flail Snail's Shell defense?
How to halve redstone signal strength?
Did silent film actors actually say their lines or did they simply improvise “dialogue” while being filmed?
What could prevent players from leaving an island?
Decode a variable-length quantity
Count number of occurences of particular numbers in list
If someone else uploads my GPL'd code to Github without my permission, is that a copyright violation?
What is the bio-mechanical plausibility of a fox with venomous fangs?
What word best describes someone who likes to do everything on his own?
Can ads on a page read my password?
What are the examples (applications) of the MIPs in which the objective function has nonzero coefficients for only continuous variables?
Are children a reason to be rejected for a job?
Why do proponents of guns oppose gun competency tests?
How can glass marbles naturally occur in a desert?
Decode a variable-length quantity
Manchester encode a data streamCircular shift an arbitrary byte-array bitwiseDisplay a MIDI TrackOutput MSB-set aligned, delimited ASCIIBit Manipulator/ReaderBinary Countdown LengthThese are the Frequencies, KennethGolf a bit-reversal tableDecode a 7-segment displayCorrupting A Binary File By Interpreting It As Text
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
A variable-length quantity (also referred to as VLQ or uintvar) is a way to encode up to a 28 bit integer value using only as many bytes as necessary. This was used in MIDI file format as a way to minimize the size of certain event data.
The way it works is fairly simple. As a big-endian series of bytes, the most significant bit (MSB) of each byte is a 1 to indicate that another VLQ byte follows. The remaining 7 bits of each byte make up the decoded value.
Example (from Wikipedia):
[ 0x86, 0xc3, 0x17 ] => 106903

Additional references: Wikipedia, Some Guy.
Challenge:
Given a variable-length quantity, convert it to it's integer value.
Input:
A list of one to four bytes or a 32-bit value type representing a valid VLQ of an integer.
Output:
The integer value of the VLQ input.
Rules and scoring:
- This is code-golf, so shortest answer in bytes for each language wins.
Standard rules and default I/O rules apply.
Loopholes forbidden (of course).- Please provide link with a test for your code (TIO.run, etc).
- A clear explanation for your answer is highly recommended.
- Built-ins that handle this conversion are not banned, however not using them is a lot more interesting.
Test cases:
Input (VLQ) Output (int)
[ 0x00 ] => 0
[ 0x07 ] => 7
[ 0x7f ] => 127
[ 0x81, 0x00 ] => 128
[ 0xC0, 0x00 ] => 8192
[ 0xff, 0x7f ] => 16383
[ 0x81, 0x80, 0x00 ] => 16384
[ 0x86, 0xc3, 0x17 ] => 106903
[ 0xbd, 0x84, 0x40 ] => 1000000
[ 0xff, 0xff, 0x7f ] => 2097151
[ 0xC0, 0x80, 0x80, 0x00 ] => 134217728
[ 0xFF, 0xFF, 0xFF, 0x7F ] => 268435455
Note: you are not required to use hex literals to represent a byte as your input or output. You may use decimal literal ([ 129, 128, 0 ]), integer (0x818000) or any other reasonable byte/octet representation if better suited to your platform. Format is flexible as long as it represents 1-4 byte/octets.
Golf away!
code-golf conversion bitwise
$endgroup$
add a comment |
$begingroup$
A variable-length quantity (also referred to as VLQ or uintvar) is a way to encode up to a 28 bit integer value using only as many bytes as necessary. This was used in MIDI file format as a way to minimize the size of certain event data.
The way it works is fairly simple. As a big-endian series of bytes, the most significant bit (MSB) of each byte is a 1 to indicate that another VLQ byte follows. The remaining 7 bits of each byte make up the decoded value.
Example (from Wikipedia):
[ 0x86, 0xc3, 0x17 ] => 106903

Additional references: Wikipedia, Some Guy.
Challenge:
Given a variable-length quantity, convert it to it's integer value.
Input:
A list of one to four bytes or a 32-bit value type representing a valid VLQ of an integer.
Output:
The integer value of the VLQ input.
Rules and scoring:
- This is code-golf, so shortest answer in bytes for each language wins.
Standard rules and default I/O rules apply.
Loopholes forbidden (of course).- Please provide link with a test for your code (TIO.run, etc).
- A clear explanation for your answer is highly recommended.
- Built-ins that handle this conversion are not banned, however not using them is a lot more interesting.
Test cases:
Input (VLQ) Output (int)
[ 0x00 ] => 0
[ 0x07 ] => 7
[ 0x7f ] => 127
[ 0x81, 0x00 ] => 128
[ 0xC0, 0x00 ] => 8192
[ 0xff, 0x7f ] => 16383
[ 0x81, 0x80, 0x00 ] => 16384
[ 0x86, 0xc3, 0x17 ] => 106903
[ 0xbd, 0x84, 0x40 ] => 1000000
[ 0xff, 0xff, 0x7f ] => 2097151
[ 0xC0, 0x80, 0x80, 0x00 ] => 134217728
[ 0xFF, 0xFF, 0xFF, 0x7F ] => 268435455
Note: you are not required to use hex literals to represent a byte as your input or output. You may use decimal literal ([ 129, 128, 0 ]), integer (0x818000) or any other reasonable byte/octet representation if better suited to your platform. Format is flexible as long as it represents 1-4 byte/octets.
Golf away!
code-golf conversion bitwise
$endgroup$
$begingroup$
Is the last byte of the input guaranteed to be < 128? Or do we need to support cases such as[0x01, 0x80, 0x02] => 1?
$endgroup$
– Arnauld
8 hours ago
$begingroup$
Inputs are guaranteed to be valid VLQ values, so last byte will always be MSB = 0.
$endgroup$
– gwaugh
8 hours ago
3
$begingroup$
@Arnauld I see better now what you were getting at, and in retrospect the case you mention would have been good to have required. In MIDI, for example, you'll be reading a stream of data and so you don't necessarily know which byte is the last one. The way it is written, guaranteeing that the last byte in the list is the last byte in the VLQ makes the MSB irrelevant and in fact kind of defeats the purpose of VLQ. As in, you wouldn't necessarily be able to use these (valid for the challenge) routines for MIDI file decoding. Totally my bad! Should have kept this in sandbox much longer...
$endgroup$
– gwaugh
6 hours ago
3
$begingroup$
This is partly my bad as well because I think I've seen the challenge in the sandbox and didn't pay enough attention. But yes, that's what I had in mind: given a list of bytes, either output the first VLQ value or output all VLQ values.
$endgroup$
– Arnauld
6 hours ago
add a comment |
$begingroup$
A variable-length quantity (also referred to as VLQ or uintvar) is a way to encode up to a 28 bit integer value using only as many bytes as necessary. This was used in MIDI file format as a way to minimize the size of certain event data.
The way it works is fairly simple. As a big-endian series of bytes, the most significant bit (MSB) of each byte is a 1 to indicate that another VLQ byte follows. The remaining 7 bits of each byte make up the decoded value.
Example (from Wikipedia):
[ 0x86, 0xc3, 0x17 ] => 106903

Additional references: Wikipedia, Some Guy.
Challenge:
Given a variable-length quantity, convert it to it's integer value.
Input:
A list of one to four bytes or a 32-bit value type representing a valid VLQ of an integer.
Output:
The integer value of the VLQ input.
Rules and scoring:
- This is code-golf, so shortest answer in bytes for each language wins.
Standard rules and default I/O rules apply.
Loopholes forbidden (of course).- Please provide link with a test for your code (TIO.run, etc).
- A clear explanation for your answer is highly recommended.
- Built-ins that handle this conversion are not banned, however not using them is a lot more interesting.
Test cases:
Input (VLQ) Output (int)
[ 0x00 ] => 0
[ 0x07 ] => 7
[ 0x7f ] => 127
[ 0x81, 0x00 ] => 128
[ 0xC0, 0x00 ] => 8192
[ 0xff, 0x7f ] => 16383
[ 0x81, 0x80, 0x00 ] => 16384
[ 0x86, 0xc3, 0x17 ] => 106903
[ 0xbd, 0x84, 0x40 ] => 1000000
[ 0xff, 0xff, 0x7f ] => 2097151
[ 0xC0, 0x80, 0x80, 0x00 ] => 134217728
[ 0xFF, 0xFF, 0xFF, 0x7F ] => 268435455
Note: you are not required to use hex literals to represent a byte as your input or output. You may use decimal literal ([ 129, 128, 0 ]), integer (0x818000) or any other reasonable byte/octet representation if better suited to your platform. Format is flexible as long as it represents 1-4 byte/octets.
Golf away!
code-golf conversion bitwise
$endgroup$
A variable-length quantity (also referred to as VLQ or uintvar) is a way to encode up to a 28 bit integer value using only as many bytes as necessary. This was used in MIDI file format as a way to minimize the size of certain event data.
The way it works is fairly simple. As a big-endian series of bytes, the most significant bit (MSB) of each byte is a 1 to indicate that another VLQ byte follows. The remaining 7 bits of each byte make up the decoded value.
Example (from Wikipedia):
[ 0x86, 0xc3, 0x17 ] => 106903

Additional references: Wikipedia, Some Guy.
Challenge:
Given a variable-length quantity, convert it to it's integer value.
Input:
A list of one to four bytes or a 32-bit value type representing a valid VLQ of an integer.
Output:
The integer value of the VLQ input.
Rules and scoring:
- This is code-golf, so shortest answer in bytes for each language wins.
Standard rules and default I/O rules apply.
Loopholes forbidden (of course).- Please provide link with a test for your code (TIO.run, etc).
- A clear explanation for your answer is highly recommended.
- Built-ins that handle this conversion are not banned, however not using them is a lot more interesting.
Test cases:
Input (VLQ) Output (int)
[ 0x00 ] => 0
[ 0x07 ] => 7
[ 0x7f ] => 127
[ 0x81, 0x00 ] => 128
[ 0xC0, 0x00 ] => 8192
[ 0xff, 0x7f ] => 16383
[ 0x81, 0x80, 0x00 ] => 16384
[ 0x86, 0xc3, 0x17 ] => 106903
[ 0xbd, 0x84, 0x40 ] => 1000000
[ 0xff, 0xff, 0x7f ] => 2097151
[ 0xC0, 0x80, 0x80, 0x00 ] => 134217728
[ 0xFF, 0xFF, 0xFF, 0x7F ] => 268435455
Note: you are not required to use hex literals to represent a byte as your input or output. You may use decimal literal ([ 129, 128, 0 ]), integer (0x818000) or any other reasonable byte/octet representation if better suited to your platform. Format is flexible as long as it represents 1-4 byte/octets.
Golf away!
code-golf conversion bitwise
code-golf conversion bitwise
asked 8 hours ago
gwaughgwaugh
3,9161 gold badge9 silver badges26 bronze badges
3,9161 gold badge9 silver badges26 bronze badges
$begingroup$
Is the last byte of the input guaranteed to be < 128? Or do we need to support cases such as[0x01, 0x80, 0x02] => 1?
$endgroup$
– Arnauld
8 hours ago
$begingroup$
Inputs are guaranteed to be valid VLQ values, so last byte will always be MSB = 0.
$endgroup$
– gwaugh
8 hours ago
3
$begingroup$
@Arnauld I see better now what you were getting at, and in retrospect the case you mention would have been good to have required. In MIDI, for example, you'll be reading a stream of data and so you don't necessarily know which byte is the last one. The way it is written, guaranteeing that the last byte in the list is the last byte in the VLQ makes the MSB irrelevant and in fact kind of defeats the purpose of VLQ. As in, you wouldn't necessarily be able to use these (valid for the challenge) routines for MIDI file decoding. Totally my bad! Should have kept this in sandbox much longer...
$endgroup$
– gwaugh
6 hours ago
3
$begingroup$
This is partly my bad as well because I think I've seen the challenge in the sandbox and didn't pay enough attention. But yes, that's what I had in mind: given a list of bytes, either output the first VLQ value or output all VLQ values.
$endgroup$
– Arnauld
6 hours ago
add a comment |
$begingroup$
Is the last byte of the input guaranteed to be < 128? Or do we need to support cases such as[0x01, 0x80, 0x02] => 1?
$endgroup$
– Arnauld
8 hours ago
$begingroup$
Inputs are guaranteed to be valid VLQ values, so last byte will always be MSB = 0.
$endgroup$
– gwaugh
8 hours ago
3
$begingroup$
@Arnauld I see better now what you were getting at, and in retrospect the case you mention would have been good to have required. In MIDI, for example, you'll be reading a stream of data and so you don't necessarily know which byte is the last one. The way it is written, guaranteeing that the last byte in the list is the last byte in the VLQ makes the MSB irrelevant and in fact kind of defeats the purpose of VLQ. As in, you wouldn't necessarily be able to use these (valid for the challenge) routines for MIDI file decoding. Totally my bad! Should have kept this in sandbox much longer...
$endgroup$
– gwaugh
6 hours ago
3
$begingroup$
This is partly my bad as well because I think I've seen the challenge in the sandbox and didn't pay enough attention. But yes, that's what I had in mind: given a list of bytes, either output the first VLQ value or output all VLQ values.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
Is the last byte of the input guaranteed to be < 128? Or do we need to support cases such as
[0x01, 0x80, 0x02] => 1?$endgroup$
– Arnauld
8 hours ago
$begingroup$
Is the last byte of the input guaranteed to be < 128? Or do we need to support cases such as
[0x01, 0x80, 0x02] => 1?$endgroup$
– Arnauld
8 hours ago
$begingroup$
Inputs are guaranteed to be valid VLQ values, so last byte will always be MSB = 0.
$endgroup$
– gwaugh
8 hours ago
$begingroup$
Inputs are guaranteed to be valid VLQ values, so last byte will always be MSB = 0.
$endgroup$
– gwaugh
8 hours ago
3
3
$begingroup$
@Arnauld I see better now what you were getting at, and in retrospect the case you mention would have been good to have required. In MIDI, for example, you'll be reading a stream of data and so you don't necessarily know which byte is the last one. The way it is written, guaranteeing that the last byte in the list is the last byte in the VLQ makes the MSB irrelevant and in fact kind of defeats the purpose of VLQ. As in, you wouldn't necessarily be able to use these (valid for the challenge) routines for MIDI file decoding. Totally my bad! Should have kept this in sandbox much longer...
$endgroup$
– gwaugh
6 hours ago
$begingroup$
@Arnauld I see better now what you were getting at, and in retrospect the case you mention would have been good to have required. In MIDI, for example, you'll be reading a stream of data and so you don't necessarily know which byte is the last one. The way it is written, guaranteeing that the last byte in the list is the last byte in the VLQ makes the MSB irrelevant and in fact kind of defeats the purpose of VLQ. As in, you wouldn't necessarily be able to use these (valid for the challenge) routines for MIDI file decoding. Totally my bad! Should have kept this in sandbox much longer...
$endgroup$
– gwaugh
6 hours ago
3
3
$begingroup$
This is partly my bad as well because I think I've seen the challenge in the sandbox and didn't pay enough attention. But yes, that's what I had in mind: given a list of bytes, either output the first VLQ value or output all VLQ values.
$endgroup$
– Arnauld
6 hours ago
$begingroup$
This is partly my bad as well because I think I've seen the challenge in the sandbox and didn't pay enough attention. But yes, that's what I had in mind: given a list of bytes, either output the first VLQ value or output all VLQ values.
$endgroup$
– Arnauld
6 hours ago
add a comment |
11 Answers
11
active
oldest
votes
$begingroup$
Pari/GP, 24 bytes
a->fromdigits(a%128,128)
Try it online!
$endgroup$
add a comment |
$begingroup$
Jelly, 6 bytes
%Ø⁷ḅØ⁷
Try it online!
Equivalent to alephalpha's Pari/GP answer.
Method: Given $n$, output $n mod 128$, converted from base $128$ to decimal.
$endgroup$
add a comment |
$begingroup$
APL (dzaima/APL), 8 bytes
128(⊣⊥|)
Try it online!
How:
128(⊣⊥|) ⍝ Anonymous function
128 | ⍝ Input modulo 128
⊣⊥ ⍝ Decoded from base 128
$endgroup$
add a comment |
$begingroup$
JavaScript (ES6), 29 bytes
-2 bytes thanks to @Shaggy
Takes input as an array of bytes.
a=>a.map(p=c=>p=p<<7|c&127)|p
Try it online!
$endgroup$
add a comment |
$begingroup$
05AB1E, 6 bytes
žy%žyβ
Try it online!
ಠ_ಠ Why do both Jelly and 05AB1E have 2-byte constants for 128? Well... It's $2^7$. But surely those bytes could be used for something better, right?
$endgroup$
add a comment |
$begingroup$
APL+WIN, 22 bytes
Prompts for a vector of integers:
2⊥¯32↑,0 1↓⍉(8⍴2)⊤¯4↑⎕
Try it online! Courtesy of Dyalog Classic
Explanation:
¯4↑⎕ Pad the vector to 4 integers from the right.
⍉(8⍴2)⊤ Convert to a matrix of 8 bit values.
,0 1↓ drop the MSBs and flatten to a vector.
2⊥¯32↑ pad bit vector to 32 bits starting at LSB and convert back to integer.
$endgroup$
add a comment |
$begingroup$
Japt, 10 8 bytes
Takes input as an array of integers.
muIÑ ìIÑ
Try it or run all test cases (header in both converts from input format used in challenge)
Saved 2 bytes by taking inspiration from alephalpha's solution.
muIÑ ìIÑ :Implicit input of integer array
m :Map
u : Modulo
I : 64
Ñ : Multiply by 2
ì :Convert to decimal
IÑ : From base 64*2
$endgroup$
add a comment |
$begingroup$
Stax, 12 bytes
ü╫ôà¡k2Wù}a☺
Run and debug it at staxlang.xyz!
Unpacked (14 bytes) and explanation:
rk128%128i^#*+
r Reverse 'cuz big-endian
k Fold from the left using block:
128% Modulize by 128
128i^# Push 128 to the power of (one plus the iteration index)
* Multiply
+ Add to the total
Implicit print
Stax has builtin base conversion, but it only works on strings. It almost works on lists of integers, though; the problem is in Stax's handling of 0.
A string is a list of integers. When you're using such a list as a string, any zeroes are automatically converted to 32 as a nice shorthand for spaces. Since the builtin |b for base conversion treats its operand as a string rather than as a raw list of integers, any case with a zero will fail.
10 bytes, fails on zeroes
Ç┘_A♥∙QZ►╣
{128%m128|b Unpacked
improve this answer
$endgroup$
add a comment a☺
Run and debug it at staxlang.xyz!
Unpacked (14 bytes) and explanation:
rk128%128i^#*+
r Reverse 'cuz big-endian
k Fold from the left using block:
128% Modulize by 128
128i^# Push 128 to the power of (one plus the iteration index)
* Multiply
+ Add to the total
Implicit print
Stax has builtin base conversion, but it only works on strings. It almost works on lists of integers, though; the problem is in Stax's handling of 0.
A string is a list of integers. When you're using such a list as a string, any zeroes are automatically converted to 32 as a nice shorthand for spaces. Since the builtin |b for base conversion treats its operand as a string rather than as a raw list of integers, any case with a zero will fail.
10 bytes, fails on zeroes
Ç┘_A♥∙QZ►╣
{128%m128|b Unpacked
b Convert from base 128
Run and debug it at staxlang.xyz!
edited 4 hours ago
answered 4 hours ago
Khuldraeseth na'BaryaKhuldraeseth na'Barya
1,7858 silver badges31 bronze badges
1,7858 silver badges31 bronze badges
add a comment |
add a comment |
$begingroup$
Charcoal, 11 bytes
I↨﹪θ¹²⁸¦¹²⁸
Try it online! Link is to verbose version of code. Takes input as an array. Explanation:
θ Input array
﹪ ¹²⁸ Elementwise modulo 128
↨ ¹²⁸ Convert from base 128
I Cast to string for implicit print
$endgroup$
add a comment |
$begingroup$
Charcoal, 11 bytes
I↨﹪θ¹²⁸¦¹²⁸
Try it online! Link is to verbose version of code. Takes input as an array. Explanation:
θ Input array
﹪ ¹²⁸ Elementwise modulo 128
↨ ¹²⁸ Convert from base 128
I Cast to string for implicit print
$endgroup$
add a comment |
$begingroup$
Charcoal, 11 bytes
I↨﹪θ¹²⁸¦¹²⁸
Try it online! Link is to verbose version of code. Takes input as an array. Explanation:
θ Input array
﹪ ¹²⁸ Elementwise modulo 128
↨ ¹²⁸ Convert from base 128
I Cast to string for implicit print
$endgroup$
Charcoal, 11 bytes
I↨﹪θ¹²⁸¦¹²⁸
Try it online! Link is to verbose version of code. Takes input as an array. Explanation:
θ Input array
﹪ ¹²⁸ Elementwise modulo 128
↨ ¹²⁸ Convert from base 128
I Cast to string for implicit print
answered 2 hours ago
NeilNeil
86.8k8 gold badges46 silver badges183 bronze badges
86.8k8 gold badges46 silver badges183 bronze badges
add a comment |
add a comment |
$begingroup$
Wolfram Language (Mathematica), 25 bytes
Fold[128#+#2&,#~Mod~128]&
Try it online!
Wolfram Language (Mathematica), 25 bytes
#~Mod~128~FromDigits~128&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 25 bytes
Fold[128#+#2&,#~Mod~128]&
Try it online!
Wolfram Language (Mathematica), 25 bytes
#~Mod~128~FromDigits~128&
Try it online!
$endgroup$
add a comment |
$begingroup$
Wolfram Language (Mathematica), 25 bytes
Fold[128#+#2&,#~Mod~128]&
Try it online!
Wolfram Language (Mathematica), 25 bytes
#~Mod~128~FromDigits~128&
Try it online!
$endgroup$
Wolfram Language (Mathematica), 25 bytes
Fold[128#+#2&,#~Mod~128]&
Try it online!
Wolfram Language (Mathematica), 25 bytes
#~Mod~128~FromDigits~128&
Try it online!
edited 2 hours ago
answered 2 hours ago
RomanRoman
5331 silver badge6 bronze badges
5331 silver badge6 bronze badges
add a comment |
add a comment |
$begingroup$
PHP, 42 bytes
foreach($argv as$a)$r=$r<<7|$a&127;echo$r;
Try it online! and verify all test cases.
Input via command line args, output to STDOUT.
$endgroup$
add a comment |
$begingroup$
PHP, 42 bytes
foreach($argv as$a)$r=$r<<7|$a&127;echo$r;
Try it online! and verify all test cases.
Input via command line args, output to STDOUT.
$endgroup$
add a comment |
$begingroup$
PHP, 42 bytes
foreach($argv as$a)$r=$r<<7|$a&127;echo$r;
Try it online! and verify all test cases.
Input via command line args, output to STDOUT.
$endgroup$
PHP, 42 bytes
foreach($argv as$a)$r=$r<<7|$a&127;echo$r;
Try it online! and verify all test cases.
Input via command line args, output to STDOUT.
edited 7 hours ago
answered 8 hours ago
gwaughgwaugh
3,9161 gold badge9 silver badges26 bronze badges
3,9161 gold badge9 silver badges26 bronze badges
add a comment |
add a comment |
If this is an answer to a challenge…
…Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.
…Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
Explanations of your answer make it more interesting to read and are very much encouraged.…Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.
More generally…
…Please make sure to answer the question and provide sufficient detail.
…Avoid asking for help, clarification or responding to other answers (use comments instead).
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f189471%2fdecode-a-variable-length-quantity%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
$begingroup$
Is the last byte of the input guaranteed to be < 128? Or do we need to support cases such as
[0x01, 0x80, 0x02] => 1?$endgroup$
– Arnauld
8 hours ago
$begingroup$
Inputs are guaranteed to be valid VLQ values, so last byte will always be MSB = 0.
$endgroup$
– gwaugh
8 hours ago
3
$begingroup$
@Arnauld I see better now what you were getting at, and in retrospect the case you mention would have been good to have required. In MIDI, for example, you'll be reading a stream of data and so you don't necessarily know which byte is the last one. The way it is written, guaranteeing that the last byte in the list is the last byte in the VLQ makes the MSB irrelevant and in fact kind of defeats the purpose of VLQ. As in, you wouldn't necessarily be able to use these (valid for the challenge) routines for MIDI file decoding. Totally my bad! Should have kept this in sandbox much longer...
$endgroup$
– gwaugh
6 hours ago
3
$begingroup$
This is partly my bad as well because I think I've seen the challenge in the sandbox and didn't pay enough attention. But yes, that's what I had in mind: given a list of bytes, either output the first VLQ value or output all VLQ values.
$endgroup$
– Arnauld
6 hours ago