An approach I've used:  count the number of leading 0 bits, say `n`.  The size of the number is then 2^n bytes (including the leading 0 bits).  Take the bits after the first 1 bit as an integer, and add the maximum value (plus one) that can be represented by a number using this encoding in 2^(n-1) bytes.

Thus, 0b10000000 -> 0, 0b11111111 -> 127, 0b01000000 00000000 -> 128, etc.

This scheme allows any non-negative value to be represented in exactly one way.