Compartilhar via


2.2.2.2.1.2.1.3 Two-Byte Signed Encoding (TWO_BYTE_SIGNED_ENCODING)

The TWO_BYTE_SIGNED_ENCODING structure is used to encode a value in the range -0x3FFF to 0x3FFF by using a variable number of bytes. For example, -0x1A1B is encoded as { 0xDA, 0x1B }, and -0x0002 is encoded as { 0x42 }. The most significant bits of the first byte encode the number of bytes in the structure and the sign.


0


1


2


3


4


5


6


7


8


9

1
0


1


2


3


4


5


6


7


8


9

2
0


1


2


3


4


5


6


7


8


9

3
0


1

c

s

val1

val2 (optional)

c (1 bit): A 1-bit, unsigned integer field containing an encoded representation of the number of bytes in this structure.

Value

Meaning

ONE_BYTE_VAL

0

Implies that the optional val2 field is not present. Hence, the structure is 1 byte in size.

TWO_BYTE_VAL

1

Implies that the optional val2 field is present. Hence, the structure is 2 bytes in size.

s (1 bit): A 1-bit, unsigned integer field containing an encoded representation of whether the value is positive or negative.

Value

Meaning

POSITIVE_VAL

0

Implies that the value represented by this structure is positive.

NEGATIVE_VAL

1

Implies that the value represented by this structure is negative.

val1 (6 bits): A 6-bit, unsigned integer field containing the most significant 6 bits of the value represented by this structure.

val2 (1 byte): An 8-bit, unsigned integer containing the least significant bits of the value represented by this structure.