delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/03/28/19:32:20

Message-ID: <38E1019E.B5E2F47C@corel.com>
Date: Tue, 28 Mar 2000 14:01:50 -0500
From: Jonathan Meunier <jonathanm AT corel DOT com>
X-Mailer: Mozilla 4.7 [en] (Win95; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: help with a bit stream....
References: <38E0FCF9 DOT AB82C211 AT gtcom DOT net>
NNTP-Posting-Host: 120.150.3.42
X-Trace: 28 Mar 2000 14:00:56 -0500, 120.150.3.42
Lines: 43
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Read one byte at a time, then simply AND this byte for each bit you want
to read..

eg:
#define BYTE char

BYTE read_bit( BYTE byte_to_process, BYTE which_bit )
{
  return ( byte_to_process & ( 1 << which_bit );

}

int main()
{
  ...
  byte = fread(...); // or whatever function you use
  bit = read_bit( byte, x );

  ...
}

HTH,
	.(Trancelucid).
	  .  Jaune  .

Krogg wrote:
> 
> I can open FILEs and read them one byte at a time but i
> really want to read them one BIT at a time...Is there
> a nice way to do this?...
> 
> something like this..
> 
> //-------------
> 
> while( (x=next_bit_in(MY_FILE))!=EOF) ;
> {
>  process_this_bit(x);
> }
> 
> //---------------
> 
> Thanks....

- Raw text -


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