Simple Algorithm
Note below that this is the Rice-Golomb encoding, where the remainder code uses simple truncated binary encoding, also named "Rice coding" (other varying-length binary encodings, like arithmetic or Huffman encodings, are possible for the remainder codes, if the statistic distribution of remainder codes is not flat, and notably when not all possible remainders after the division are used). In this algorithm, if the M parameter is a power of 2, it becomes equivalent to the simpler Rice encoding.
- Fix the parameter M to an integer value.
- For N, the number to be encoded, find
- quotient = q = int
- remainder = r = N modulo M
- Generate Codeword
- The Code format :
, where - Quotient Code (in unary coding)
- Write a q-length string of 1 bits
- Write a 0 bit
- Remainder Code (in truncated binary encoding)
- If M is power of 2, code remainder as binary format. So bits are needed. (Rice code)
- If M is not a power of 2, set
- If code r as plain binary using b-1 bits.
- If code the number in plain binary representation using b bits.
- The Code format :
Read more about this topic: Golomb Coding
Famous quotes containing the word simple:
“Even the simple act that we call going to visit a person of our acquaintance is in part an intellectual act. We fill the physical appearance of the person we see with all the notions we have about him, and in the totality of our impressions about him, these notions play the most important role.”
—Marcel Proust (18711922)