Bit Masking Question
J. Horsmeier
jos at and.nl
Mon Jun 24 20:56:08 AEST 1991
In article <12191 at hub.ucsb.edu> angst at cs.ucsb.edu (Hopelessly in love w/Donna Reed) writes:
>What I'm doing is reading characters from a file and I'd like to
>categorise the characters into 3 groups based on their 2 most-
[...]
>
> #define FMASK 0xC0
> #define RMASK 0x80
> int c;
> switch (c & FMASK) {
[ normal cases ...]
> case 0x0:
> case 0x40:
> Do stuff for group 3
^^^^^^ Make this the default ...
> ...
>
> default:
> fprintf (stderr, "bad news!\n");
^^^^^^ this is the same kind of paranoia as:
for (i= 0; i < 10; i++)
if (i >= 10) ZombyWoof();
> }
>
>This seems to work, but I'd like comments. Is there a better way to
>do this? Should I make #define's for 0x0 and 0x40? Is there a way
>to #define bits?o
This is not really much of a problem is it? Your code works fine,
it's compact, fast etc. It'll do the job :-)
Jos
+----------------------------------------------------------------------+
|O J.A. Horsmeier AND Software B.V. phone : +31 10 4367100 O|
|O Westersingel 106/108 fax : +31 10 4367110 O|
|O 3015 LD Rotterdam NL e-mail: jos at and.nl O|
|O--------------------------------------------------------------------O|
|O I am a Hamburger (F. Zappa 1974) O|
+----------------------------------------------------------------------+
More information about the Comp.lang.c
mailing list