Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Golomb coding
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Simple algorithm == Below 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'' = floor(''N''/''M'') ## remainder = ''r'' = ''N'' modulo ''M'' # Generate codeword ## The code format : <Quotient code><Remainder code>, where ## Quotient code (in [[unary coding]]) ### Write a ''q''-length string of 1 bits (alternatively, of 0 bits) ### Write a 0 bit (respectively, a 1 bit) ## Remainder code (in [[truncated binary encoding]]) ### Let <math>b = \lfloor\log_2(M)\rfloor</math> #### If <math>r < 2^{b+1}-M</math> code ''r'' in binary representation using ''b'' bits. #### If <math>r \ge 2^{b+1}-M</math> code the number <math>r+2^{b+1}-M</math> in binary representation using ''b'' + 1 bits. Decoding: # Decode the unary representation of ''q'' (count the number of 1 in the beginning of the code) # Skip the 0 delimiter # Let <math>b = \lfloor\log_2(M)\rfloor</math> ## Interpret next ''b'' bits as a binary number ''r'''. If <math>r' < 2^{b+1}-M</math> holds, then the remainder <math> r = r' </math> ## Otherwise interpret ''b + 1'' bits as a binary number ''r''', the remainder is given by <math>r = r' - 2^{b+1} + M</math> # Compute <math>N = q * M + r</math>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)