Sha256: e0c1b4604f3ac78da3882086ec8588665d226fb9e0783967b0cb7d2e346fb815

Contents?: true

Size: 1.89 KB

Versions: 107

Compression:

Stored size: 1.89 KB

Contents

# Variable Length Quantity

Implement variable length quantity encoding and decoding.

The goal of this exercise is to implement [VLQ](https://en.wikipedia.org/wiki/Variable-length_quantity) encoding/decoding.

In short, the goal of this encoding is to encode integer values in a way that would save bytes.
Only the first 7 bits of each byte is significant (right-justified; sort of like an ASCII byte). 
So, if you have a 32-bit value, you have to unpack it into a series of 7-bit bytes. 
Of course, you will have a variable number of bytes depending upon your integer. 
To indicate which is the last byte of the series, you leave bit #7 clear.
In all of the preceding bytes, you set bit #7. 

So, if an integer is between `0-127`, it can be represented as one byte. 
Although VLQ can deal with numbers of arbitrary sizes, for this exercise we will restrict ourselves to only numbers that fit in a 32-bit unsigned integer.
Here are examples of integers as 32-bit values, and the variable length quantities that they translate to:


```
 NUMBER        VARIABLE QUANTITY
00000000              00
00000040              40
0000007F              7F
00000080             81 00
00002000             C0 00
00003FFF             FF 7F
00004000           81 80 00
00100000           C0 80 00
001FFFFF           FF FF 7F
00200000          81 80 80 00
08000000          C0 80 80 00
0FFFFFFF          FF FF FF 7F
```

## Making the Test Suite Pass

1. Get [PHPUnit].

        % wget --no-check-certificate https://phar.phpunit.de/phpunit.phar
        % chmod +x phpunit.phar

2. Execute the tests for an assignment.

        % phpunit.phar wordy/wordy_test.php

[PHPUnit]: http://phpunit.de


## Source

A poor Splice developer having to implement MIDI encoding/decoding. [https://splice.com](https://splice.com)

## Submitting Incomplete Solutions
It's possible to submit an incomplete solution so you can see how others have completed the exercise.

Version data entries

107 entries across 107 versions & 1 rubygems

Version Path
trackler-2.2.1.103 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.102 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.101 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.100 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.99 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.98 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.97 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.96 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.95 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.94 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.93 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.92 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.91 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.90 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.89 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.88 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.87 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.86 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.85 tracks/php/exercises/variable-length-quantity/README.md
trackler-2.2.1.84 tracks/php/exercises/variable-length-quantity/README.md