I need to implement Elias Gamma Encoder/Decoder for a sequence of
integers, using the C programming language. My main confuse is how
people do the bit-level programmng in the process of encoding and
decoding.
Because the number of bits for representing each integer is different
and all operations deal with bits, should I just apply for a large
chunk of memory, which stores the bit stream from the encoding of the
integer sequence ? Should I then work on bit by bit in that memory
space during the process of encoding and decoding ? Or is there any C
library function that I can use to easy the bit-level operations ?
Is there any sample C code for the Elias Gamma Encoder/Decoder ? What
I can find on wiki is C++ code, using some high-level pre-constructed
classes for the bit-level operations, without the details on the
actual bit-level operations.
I am a postdoc researcher and working on implementing compressed data
structures, where this Gamma coding is a component. I am not a student
looking for homework solutions here.
Thank you very much !
The online manual references logical http://www.acm.uiuc.edu/webmonkeys/book/c_guide/1.5.html
I use a compare to a controlled variable. I set a variable to the
correct "Power of 2" and compare with a logical test.
with this simple segment the variable of type char test if some data
is a set bit or not and set a bit in another data if it is.
if( *source_obj_ptr & source_obj_pwr ) { *work_obj_file |=
work_obj_pwr;}
I believe swaping the "|=" for a "^=" resets that bit.
I'm sure others have better code.
I find it easy to handle it that way.
Anyway it's a good direction if not the best direction. I could
stand to learn something new on coding such.
This query got little response. There sure *ought* to be
standard C subroutines for reading and writing bits, since most
compressors need to do that. I e-mailed some simple examples to
OP, but am curious about the details of how others do it.
Please post here! -- my Internet is too slow to go traipsing
through open source directories....
On the topic of Elias Gamma coding, I believe this is the
method where, for example, integers from 8 to 15 are encoded
as 7 bits: a 4-bit size code and 3 bits to distinguish
the 8 possibilities among 8 through 15. There are at
least three ways to do the bit mapping details:
(a) 0001xxx
(b) 0x0x0x1
(c) 0x1x1x0
("xxx" denotes the value, i.e. xxx=000 for 8, 001, for 9, etc.)
Method (a) seems easiest to implement: the code *is* the
integer itself, with appropriate number of leading zeros.
In (a) the size information is *prefiexed", in (b) it
is *suffixed*, in (c) it is, in effect, both prefix
and suffix! Which way do others do this "Elias coding"?
James Dow Allen
I seldom use elias codes except for elias omega however
I find fibonacci code easier to use. For bit IO look at
my IO routines with arb255.zip they make bijective compression
easy.
David A. Scott
--
My Crypto code
http://bijective.dogma.net/crypto/scott19u.zip
http://www.jim.com/jamesd/Kong/scott19u.zip old version
My Compression code http://bijective.dogma.net/
**TO EMAIL ME drop the roman "five" **
Disclaimer:I am in no way responsible for any of the statements
made in the above text. For all I know I might be drugged.
As a famous person once said "any cryptograhic
system is only as strong as its weakest link"
I work on embedded device programming in C, and here bit level
operations are quite frequently used.
We do not use any special library, but just the regular bit operators
available with C. Basically, different bit-fields and bit-shifts
covers all that's ever required.
But there's one helpful tutorial article (http://www.catonmat.net/blog/
low-level-bit-hacks-you-absolutely-must-know/) I came across, that
explains the common bit-level operations pretty well.
Hope this helps
-Ankur