ZigZag Integer encoding

Make all you Integer positive, while keeping them small - lemire / HN

The essence of the trick: make the sign bit the least significant bit. Then all the leading bytes for integers of small magnitude remain zeros (not 0xFF like in two-complement integers), and compression becomes easy.

This immediately makes the formula (val<<1) ^ (val>>31) intuitive.

Written on June 1, 2023, Last update on June 1, 2023
algorithm