Share via


2.3.2 Multi-byte Integers

Multi-byte integers MUST represent unsigned values and use variable length storage to represent numbers. Each byte stores 7 bits of the integer. The high-order bit of each byte indicates whether the following byte is a part of the integer. If the high-order bit is set, the lower seven bits are used and a next byte MUST be consumed. If a byte has the high-order bit cleared (meaning that the value of the byte is less than 0x80) then that byte is the last byte of the integer. The least significant byte (LSB) of the integer appears first.

The following table shows the number of bytes used to store a value in a certain range:

Range from

Range to

Encoding used

0x00000000

0x0000007F

1 byte

0x00000080

0x00003FFF

2 bytes, LSB stored first

0x00004000

0x001FFFFF

3 bytes, LSB stored first

0x00200000

0x0FFFFFFF

4 bytes, LSB stored first

0x10000000

0x7FFFFFFF

5 bytes, LSB stored first

For mb32 integers the resulting number MUST fit into a signed 32bit integer.

For mb64 integers the resulting number MUST fit into a signed 64bit integer. A parser or writer MAY<10> choose to limit the valid range of the resulting number even more.