delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/03/29/01:36:14

From: Nate Eldredge <neldredge AT hmc DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: help with a bit stream....
Date: 28 Mar 2000 16:07:13 -0800
Organization: InterWorld Communications
Lines: 94
Message-ID: <83em8uej0u.fsf@mercury.st.hmc.edu>
References: <38E0FCF9 DOT AB82C211 AT gtcom DOT net> <38E1019E DOT B5E2F47C AT corel DOT com> <38E105BC DOT E528B7F0 AT corel DOT com> <38E12ED5 DOT 7205297F AT gtcom DOT net>
NNTP-Posting-Host: mercury.st.hmc.edu
Mime-Version: 1.0
X-Trace: nntp1.interworld.net 954288530 58173 134.173.45.219 (29 Mar 2000 00:08:50 GMT)
X-Complaints-To: usenet AT nntp1 DOT interworld DOT net
NNTP-Posting-Date: 29 Mar 2000 00:08:50 GMT
User-Agent: Gnus/5.0802 (Gnus v5.8.2) Emacs/20.5
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

I suspect what you'd do is to have a buffer of at least one byte, then
return bits from this buffer, and refill it when empty.  Something
like:

int buf; /* we really only use one byte of it */
int bits_left = 0;

/* Note this reads the least significant bit first... it could be
   changed. */
int get_bit() {
        int bit;
        if (bits_left == 0) {
                buf = getc(input); /* read one byte */
                /* handle error or EOF case */
        }
        bit = buf & 1; /* get least significant bit */
        buf >>= 1;     /* shift for the next time */
        bits_left--;   /* and note that we've used one bit */
        return bit;
}

Presumably the code you have does the same thing, but associates a
buffer with each file (which is why there are the funny structs).
This allows you to get bits from multiple files at once.

Krogg <krogg DOT no DOT to DOT spam AT gtcom DOT net> writes:

> Jonathan Meunier wrote:
> > 
> > err, the read_bit() function should return:
> > return (( byte_to_process >> which_bit ) & 1 );
> > 
> > And which_bit should be between 0 and 7..
> > 
> >         .(Trancelucid).
> >           .  Jaune  .
> > 
> > Jonathan Meunier wrote:
> > >
> > > BYTE read_bit( BYTE byte_to_process, BYTE which_bit )
> > > {
> > >   return ( byte_to_process & ( 1 << which_bit );
> > > }
> 
> This method isnt what i am looking for....I know how
> to see the individual bits in a byte but i want to be
> able to say read the next n bits and see if they are 
> on or off....maybe i want the next 7 or the next 22
> bits....I found some code in the snippits archive
> that seems promising for this purpose but i am still
> trying to figure out how to implement it....
> 
> Its got functions like these: 
> 
> bfile * bfopen(char *name, char *mode);
> int     bfread(bfile *bf);
> void    bfwrite(int bit, bfile *bf);
> void    bfclose(bfile *bf);
> 
> and a struct like this:
> 
> typedef struct  {
>       FILE *  file;       /* for stream I/O   */
>       char    rbuf;       /* read bit buffer  */
>       char    rcnt;       /* read bit count   */
>       char    wbuf;       /* write bit buffer */
>       char    wcnt;       /* write bit count  */
> } bfile;
> 
> I am trying to figure out how to chop out the junk
> and use this,but if some one esle had some thing better
> i would welcome the help.
> 
> Thnaks.
>  
> 
> 
> 
> -- 
> 
> 
> |"""""<`.THE PRINCE ,'>"""""""""""""""""""""""""""""""""""|
> |      `.`/""""""\,','            my sig is too big,      |
> |SEE HIS (  /   \ \' SEE HIS      but its really cool.    |
> | FACE    \/<> <>\/   SMILE                               |
> |         /   W   \          Visit my ascii art site:     |
> |       ,'\_|||||_/`.  http://www.gtcom.net/~krogg/ascii/ |
> |     ,','   |||   `.`.     krogg DOT no DOT to DOT spam AT gtcom DOT net    |
> |____<,' TIME TO DIE `.>____Remove no.to.spam to reply____|

-- 

Nate Eldredge
neldredge AT hmc DOT edu

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019