From: Sean Proctor Newsgroups: comp.os.msdos.djgpp Subject: Re: Bits Message-ID: References: <8jdv9d$dn5$1 AT news DOT netvision DOT net DOT il> X-Newsreader: Forte Agent 1.7/32.534 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 23 Date: Thu, 29 Jun 2000 03:56:05 GMT NNTP-Posting-Host: 207.16.153.202 X-Complaints-To: Abuse Role , We Care X-Trace: newshog.newsread.com 962250965 207.16.153.202 (Wed, 28 Jun 2000 23:56:05 EDT) NNTP-Posting-Date: Wed, 28 Jun 2000 23:56:05 EDT Organization: ENTER.net (enter.net) To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com On Thu, 29 Jun 2000 01:52:04 +0300, "Avi Berkovich" wrote: >Hello > >Is there a C++ function which can manage individual bits extractions from a >file? > >For example, if I need to get 3 bits, then 5 bits, 1 bit, etc... > >Demon > ummm... here's my solution, probably not the best.. but should work. char ch; file >> ch; //rusty with my C++, read a char char bits3 = ch >> 5; //shift the 3 bits to the beginning char bits5 = ch & 0x1f; //mask out the rest... file >> ch; char bits1 = ch >> 7; I believe that works... Sean