0

I know some variable length number encodings which share the core idea that 1s encode the payload length linearly.

0
10x
110xx
1110xxx

or with 1s and Xs interleaved:

0
1x0
1x1x0
1x1x1x0

With some minor modifications (7 Xs per 1 and 7 Xs at the end) we get:

0xxxxxxx
1xxxxxxx0xxxxxxx
1xxxxxxx1xxxxxxx0xxxxxxx
1xxxxxxx1xxxxxxx1xxxxxxx0xxxxxxx

https://en.wikipedia.org/wiki/Variable-length_quantity

or:

0xxxxxxx
110xxxxx 10xxxxxx
1110xxxx 10xxxxxx 10xxxxxx
11110xxx 10xxxxxx 10xxxxxx 10xxxxxx

https://de.wikipedia.org/wiki/UTF-8

but they both scale linearly. I wanted something that scales exponentially and can be decoded bitwise in forward direction (no byte alignment, reverse decoding or random seeking needed) so I came up with:

0
1x0
1x1xx0
1x1xx1xxxx0
1x1xx1xxxx1xxxxxxxx0

Has anyone an idea if this is a thing and what it is called?

1 Answers1

0

Such an encoding is used in UTF-8. It's called Variable-width encoding

Christoph Bimminger
  • 1,006
  • 7
  • 25