Skip to content

Instantly share code, notes, and snippets.

@twyatt
Last active January 25, 2024 13:14
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save twyatt/99f329d7eb923f65f4e3c32e95fad00b to your computer and use it in GitHub Desktop.
Save twyatt/99f329d7eb923f65f4e3c32e95fad00b to your computer and use it in GitHub Desktop.
CBOR cheatsheet

CBOR cheatsheet

Major type Description Binary Shorthand
0 an unsigned integer 000_xxxxx unsigned(#)
1 a negative integer 001_xxxxx negative(#-1)
2 a byte string 010_xxxxx bytes(n)
3 a text string 011_xxxxx text(n)
4 an array of data items 100_xxxxx array(n)
5 a map of pairs of data items 101_xxxxx map(n)

1 For negative(#-1), # represents the negative value minus 1. For example, negative(4) represents a value of -5.

5 For map(n), n represents number of key/value pairs.

Quick references

Unsigned integer

Number Hex
0 .. 9 00 .. 09
10 .. 15 0A .. 0F
16 .. 23 10 .. 17
24 .. 255 18 18 .. 18 FF
256 .. 65535 19 0100 .. 19 FFFF
65536 .. 4294967295 1A 00010000 .. 1A FFFFFFFF

Negative integer

Number Hex
-1 .. -10 20 .. 29
-11 .. -16 2A .. 2F
-17 .. -24 30 .. 37
-25 .. -256 38 18 .. 38 FF
-257 .. -65536 39 0100 .. 39 FFFF
-65537 .. -4294967296 3A 00010000 .. 3A FFFFFFFF

Byte string

Length Hex
0 .. 9 40 .. 49
10 .. 15 4A .. 4F
16 .. 23 50 .. 57
24 .. 255 58 18 .. 58 FF
256 .. 65535 59 0100 .. 59 FFFF
65536 .. 4294967295 5A 00010000 .. 5A FFFFFFFF
Indefinite 5F

Text string

Length Hex
0 .. 9 60 .. 69
10 .. 15 6A .. 6F
16 .. 23 70 .. 77
24 .. 255 78 18 .. 78 FF
256 .. 65535 79 0100 .. 79 FFFF
65536 .. 4294967295 7A 00010000 .. 7A FFFFFFFF
Indefinite 7F

Array

Length Hex
0 .. 9 80 .. 89
10 .. 15 8A .. 8F
16 .. 23 90 .. 97
24 .. 255 98 18 .. 98 FF
256 .. 65535 99 0100 .. 99 FFFF
65536 .. 4294967295 9A 00010000 .. 9A FFFFFFFF
Indefinite 9F

Map

Length Hex
0 .. 9 A0 .. A9
10 .. 15 AA .. AF
16 .. 23 B0 .. B7
24 .. 255 B8 18 .. B8 FF
256 .. 65535 B9 0100 .. B9 FFFF
65536 .. 4294967295 BA 00010000 .. BA FFFFFFFF
Indefinite BF

Length represents number of key/value pairs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment