Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!hp4nl!and!jos From: jos@and.nl (J. Horsmeier) Newsgroups: comp.lang.c Subject: Re: Bit Masking Question Message-ID: <980@baby.and.nl> Date: 24 Jun 91 10:56:08 GMT References: <12191@hub.ucsb.edu> Organization: AND Software BV Rotterdam Lines: 44 In article <12191@hub.ucsb.edu> angst@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@and.nl O| |O--------------------------------------------------------------------O| |O I am a Hamburger (F. Zappa 1974) O| +----------------------------------------------------------------------+