[prog] [C] writing last x bits...
Jenn Vesperman
jenn at anthill.echidna.id.au
Fri Sep 27 13:50:17 EST 2002
On Fri, 2002-09-27 at 02:06, Annie Downs wrote:
> Hey all
>
> I only learned C last week <g> but I'm trying to write this program that takes
> a file which is in binary and prints out the last 8 bits.. some places in the
> program it needs to be more bits than that, once 16 and once 32 but i'm hoping
> the procedure would be the same.. i'm having trouble figuring out how to deal
> with this. anyone have any possible suggestions?
> thanks so much in advance..
The first step is retrieving the last X bits. I'll assume you have a
book which tells you how to read a file.
Try reading X bits into a temporary variable, and constantly re-writing
that variable until you reach EOF. Something like (this is in
pseudocode, not C):
c = read_from_file()
d = c;
while (c != EOF) {
d = c;
}
Then print d in binary mode.
Jenn V.
--
"Do you ever wonder if there's a whole section of geek culture
you miss out on by being a geek?" - Dancer.
jenn at anthill.echidna.id.au http://anthill.echidna.id.au/~jenn/
More information about the Programming
mailing list