Epistemic Status: seedling Sprouting - This is a zettelkasten-style card about a concept I’m interested in remembering.


Zigzag encoding is a space saving encoding of integers where each positive integer nn is assigned to:

2n2n

While each negative integer nn is assigned to :

2n12 \cdot \lvert{n}\rvert - 1

This has the property that the number of bits required to store an integer is proportional to its absolute value.

Protobuf and Avro Schema both use this in their binary encodings.