Skip to main content
1

Negative Integer

0x20 – 0x3bRFC 8949

CBOR major type 1 encodes negative integers. The encoded value represents -1 minus the argument. So 0x20 = -1, 0x37 = -24, 0x38 0x17 = -24. The formula is: value = -1 - argument. Range: -1 to -2^64.

Encoding

Initial byte: 0b001_XXXXX where XXXXX = additional info. Value = -1 - argument.

Major type 1 uses the same additional info encoding as major type 0 but represents negative integers. The value is computed as: decoded_value = -1 - argument.

Examples: 0x20 = argument 0 → -1 - 0 = -1 0x37 = argument 23 → -1 - 23 = -24 0x38 0x17 = argument 23 (1-byte) → -1 - 23 = -24 (same value, different encoding)

CBOR negative integers cover -1 to -(2^64), which is a larger range than either int64 or uint64 alone. The full signed integer range requires combining both major types 0 and 1.

Examples

LabelHexValue
-120-1 (argument=0, -1-0=-1)
-1029-10 (argument=9, -1-9=-10)
-2437-24 (argument=23, max direct)
-2538 18-25 (argument=24, one extra byte)
-25638 ff-256

See Also