delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/06/29/00:00:42

From: Sean Proctor <sproctor AT ccs DOT neu DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Bits
Message-ID: <nthllso95u8mkou0d408tn54000lmk7ip2@4ax.com>
References: <8jdv9d$dn5$1 AT news DOT netvision DOT net DOT il>
X-Newsreader: Forte Agent 1.7/32.534
MIME-Version: 1.0
Lines: 23
Date: Thu, 29 Jun 2000 03:56:05 GMT
NNTP-Posting-Host: 207.16.153.202
X-Complaints-To: Abuse Role <abuse AT enter DOT net>, We Care <abuse AT newsread DOT com>
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"
<berkovic AT netvision DOT net DOT il> 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

- Raw text -


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