Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: fread/fwrite Bits

Reply
Thread Tools

Re: fread/fwrite Bits

 
 
CBFalconer
Guest
Posts: n/a
 
      01-03-2004
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!


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
shifting bits, shift 32 bits on 32 bit int GGG C++ 10 07-06-2006 06:09 AM
what about unsigned and signed 8 bits number, 16 bits, etc?? sarmin kho Python 2 06-15-2004 06:40 PM
8 bits/ch vs 16 bits/ch in PS Terry Digital Photography 5 01-21-2004 06:59 PM
8-Bits vs 12 or 16 bits/pixel; When does more than 8 bits count ? Al Dykes Digital Photography 3 12-29-2003 07:08 PM
win XP 32 bits on a 64 bits processor.. Abbyss Computer Support 3 11-13-2003 12:39 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57