- This encodes an integer as a variable-length sequence of bytes (a "varint" or "VLQ" encoding).
- This code supports 2 <= base <= 255. Specializations with a constant power-of-two base are fast.
- The base should be chosen to minimize average encoding length for the expected integer distribution.
- First, the signed integer input x is zig-zag mapped to an unsigned integer intermediate.
- Nonnegative integer inputs 0, 1, 2, 3, ... are zig-zag mapped to intermediates 0, 2, 4, 6, ...
- Negative integer inputs -1, -2, -3, -4, ... are zig-zag mapped to intermediates 1, 3, 5, 7, ...
- The intermediate is then encoded using zero or more nonterminal bytes followed by one terminal byte.
- The terminal bytes for a given base are 0, 1, 2, ..., 256-base-1.
- The nonterminal bytes are 256-base, 256-base+1, 256-base+2, ..., 253, 254, 255.
- E.g., if the base is 2 the terminals are 0, 1, ..., 253. The nonterminals are 254, 255.
- E.g., if the base is 3 the terminals are 0, 1, ..., 252. The nonterminals are 253, 254, 255.
- E.g., if the base is 4 the terminals are 0, 1, ..., 251. The nonterminals are 252, 253, 254, 255.
- E.g., if the base is 5 the terminals are 0, 1, ..., 250. The nonterminals are 251, 252, 253, 254, 255.
- If the intermediate is less than 256-base, a terminal byte is emitted and the encoding is complete.
- Otherwise, the minimum possible value (i.e., 256-base) is subtracted from the intermediate.
- The intermediate is then divided by the base. A nonterminal byte encodes the remainder of this division.
- The intermediate is replaced by the quotient and is encoded recursively in the bytes that follow.

To receive a hint, submit unfixed code.