Tom Timmermann wrote:
>
> I am trying to read a binary file which has bit level codes.
>
> example with spaces added for clarity:
>
> 00 00000001 00000001 10 11 01 00001111 10
>
> 00 indicates read the next 2 bytes as short
> 10 and 11 read no further
> 01 read the next byte as unsigned char
>
> Any ideas on how to do this ?
> If I read as unsigned char and use bit shift to extract the 2 bit
> code, how do I control the file pointer position at the bit level ?
This is better suited for c.l.c, to which I have cross-posted.
Your first task is to decide on the actual file format. C bytes
are not necessarily octets, so you must first decide if each byte
can contain more than 8 bits of information or not. Then you have
to write code to convert the incoming byte stream to a bit stream,
which involves making decisions as to which end of the byte holds
the earliest bit.
You don't control the incoming file stream at the bit level. You
have to provide the appropriate buffering and manipulation.
If you limit your solutions to a world where bytes are octets, and
the earliest bit is the most significant bit in a byte, that
decision should be isolated in the stream conversion code. After
that all will be simple. All you really need then is a
getnextbit() routine.
--
Chuck F () ()
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
|