附带上解码代码:
void golombDecode(char* source, char* dest, int M)
{
BitReader bitreader(source);
IntWriter intwriter(dest);
int q = 0;
int nr = 0;
while (bitreader.hasLeft())
{
nr = 0;
q = 0;
while (bitreader.getBit()) q++; // potentially dangerous with malformed files.
for (int a = 0; a < log2(M); a++) // read out the sequential log2(M) bits
if (bitreader.getBit())
nr += 1 << a;
nr += q*M; // add the bits and the multiple of M
intwriter.putInt(nr); // write out the value
}
bitreader.close();
intwriter.close()
}