In general, to encode a number k in unary, we output k 1s, followed by a 0. We
need the 0 at the end to make the code unambiguous.
This code is very efficient for small numbers such as 0 and 1, but quickly becomes very expensive. For instance, the number 1023 can be represented in 10
binary bits, but requires 1024 bits to represent in unary code.
Now we know about two kinds of numeric encodings. Unary is convenient
because it is compact for small numbers and is inherently unambiguous. Binary
is a better choice for large numbers, but it is not inherently unambiguous. A reasonable compression scheme needs to encode frequent numbers with fewer bits
than infrequent numbers, which means binary encoding is not useful on its own
for compression.