- The function gets an array of numbers. The numbers are internally represented using binary (since computers use bits which are on or off) but generally discussed using decimal notation. To the computer, a number is a number is a number.
`20 == 0o24 == 0x14 == 0b10100`

(I think I got that right). You can use any notation/base, but a number is a number.
- For each number in the array, convert it to the VLQ encoding.
- Return the array of VLQ encoded values.

The tricky bit is step 2 – the VLQ encoding. Consider the value `128 * 128 + 128 + 25`

, also known as `16537`

or `0b1_0000000_0000000 + 0b1_0000000 + 25`

(which mixes representations!) or `0b1_0000001_0011001`

. If we split it into chunks of 7 bits, it is large enough to need three “chunks”. In VLQ encoding, this becomes three values (1, 1, 25), one chunk each. All VLQ chunks – except the last one, have the “highest” bit set, ie `0b1000_0000 == 128`

. The first two chunks, 1 and 1, become `128 (high bit)+ 1 (original value) == 129`

. The last chunk, `25`

, does not have the high bit set so it is just `25`

. Combined, `16537`

gets encoded as `129, 129, 25 == 0x81, 0x81, 25 == 0b1000_0001, 0b1000_0001, 25`

.

If the input is an array with two values, `[16537, 16537]`

then the result should be `[129, 129, 25, 129, 129, 25]`

.

Taking a number (eg `16537`

) and figuring out how to represent that in 7 bit chunks (eg `0b1_0000001_0011001`

) is easy. Write it out as a binary value then put spaces every 7 characters. To the computer, `16537`

and `0b1_0000001_0011001`

are the *exact same thing*! It’s just written slightly different with spaces added in different places for readability. No conversion needed.

However, turning `16537`

into three numbers, `[1, 1, 25]`

is where things get a bit tricky. That’s where bitwise operators become very useful. Specifically the bitwise `AND`

and bitwise right-shift operators. As a first step, lets consider if we were dealing with base 10 instead of base 2. Take the number `1234`

56. Can you convert that to `[12, 34, 56]`

somehow? If you can do that, then you can use very similar logic to convert the binary value `0b01_01_01`

into `[1, 1, 1]`

or `0b1_0000001_0011001`

into `[1, 1, 25]`

. I don’t want to spoil too much so I’ll stop myself here.