184 Integer, arithmetic, and adaptive coding
and
i = 1,...,4 → r = 0, 1, 2, 3 → suffix = 00, 01, 10, 11,
i = 5,...,8 → r = 0, 1, 2, 3 → suffix = 00, 01, 10, 11,
i = 9,...,12 → r = 0, 1, 2, 3 → suffix = 00, 01, 10, 11.
We, thus, observe that the prefix increases by one bit at each multiple of m = 4 and that
the suffix has a constant length and changes with a periodicity of m = 4. From the above
rules and with this example we obtain G(3) = 1
10, G(5) = 01 00 and G(12) = 001 11,
for instance (the underscore
being introduced for clarity). Note the prefix rule of 1
preceded by q zero bits is only conventional.
5
We can also define the prefix as 0 preceded
by q one bits, which represents the complement of the previous prefix (e.g., G(3) = 0
10,
G(5) = 10
00, and G(12) = 110 11). Another convention for the suffix is to take the
smallest number of bits for the binary representation of r , which only changes 00 into
0. Thus, we have G(3) = 1
0 instead of 1 00, G(5) = 01 0 instead of 01 00, and so on.
This convention reduces the code length by one bit each time i = km + 1(k an integer).
With their prefix increase by blocks of m and their suffix m periodicity, the Golomb
codes are straightforward to generate. Table 10.1 shows the nonoptimized Golomb code
for m = 8.
Consider next the actual Golomb code, which uses a more complicated rule (b) for
defining the suffix. This rule consists of coding the suffix with c =log
2
m bits for the
first c values of r (with 0 as the leading bit), and with c + 1 bits for the other values
(with 1 as the leading bit). Consider, for instance, m = 5. We have c =log
2
5=2.
Thus, we have, for the first 15 integers:
i = 1,...,5 → q = 0 → prefix = 1,
i = 6,...,10 → q = 1 → prefix = 01,
i = 11,...,15 → q = 2 → prefix = 001, etc.,
and
i = 1,...,5 → r = 0, 1, 2, 3, 4 → suffix = 00, 01, 100, 101, 110,
i = 6,...,10 → r = 0, 1, 2, 3, 4 → suffix = 00, 01, 100, 101, 110,
i = 11,...,15 → r = 0, 1, 2, 3, 4 → suffix = 00, 01, 100, 101, 110,
showing that in each period, the first two suffixes are coded with two bits with a leading
0, and the other suffixes are coded with three bits with a leading 1. We note that the
three-bit suffix codes do not correspond to a binary representation of r, unlike with our
previous definition. Table 10.1 shows the actual Golomb code corresponding to the case
m = 6. We observe that the second definition makes it possible to shorten the length of
5
Coding a number n by n − 1 zeros followed by a one bit is referred to as unary coding. For instance, the
numbers n = 2, n = 5, and n = 7 are represented in unary coding as 01, 00001, and 0000001, respectively.
This definition should not be confused with the “unary number representation,” which uses only one
symbol character (e.g., 1) and is defined according to the rule 0
decimal
≡ 1
unary
,1
decimal
≡ 11
unary
,2
decimal
≡
111
unary
, etc.