Integers are encoded as ordinary binary string, that has prepended byte
indicating is it positive or negative integer. Negative integers store
their absolute value the same way as positive integers. After decoding,
their value is subtracted from -1. Negative value encoded as 0x02
means -1 - 0x02 => -3
.
Shortest possible form must be used, that means no leading zero byte. 0 and -1 values are empty strings, so even they won’t have leading zero.
Example representations:
0 | 0C 80 |
1 | 0C 81 01 |
10 | 0C 81 0A |
100 | 0C 01 64 |
65536 | 0C 83 010000 |
1000000000000 | 0C 85 E8D4A51000 |
18446744073709551615 | 0C 88 FFFFFFFFFFFFFFFF |
18446744073709551616 | 0C 89 010000000000000000 |
-18446744073709551616 | 0D 88 FFFFFFFFFFFFFFFF |
-18446744073709551617 | 0D 89 010000000000000000 |
-1 | 0D 80 |
-10 | 0D 81 09 |
-100 | 0D 81 63 |
-65536 | 0D 82 FFFF |