Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!sequent!ogicse!intelhf!ichips!iWarp.intel.com!inews!pima!bhoughto From: bhoughto@pima.intel.com (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: Bit Masking Question Message-ID: <4826@inews.intel.com> Date: 24 Jun 91 06:26:51 GMT References: <12191@hub.ucsb.edu> Sender: news@inews.intel.com Organization: Intel Corp, Chandler, AZ Lines: 35 In article <12191@hub.ucsb.edu> angst@cs.ucsb.edu (Hopelessly in love w/Donna Reed) writes: Yeah, she's a babe, alright. A member of a dying breed. Unless you count that such competence has moved into the cubicles next to me with rather heartening frequency. >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- >significant bits. Group 1 has '11' in their MSb's, group 2 has >'10' in their MSb's, and group 3 has '0X' (X = don't care) in >their MSb's. The only other (sensible, non-shifting) way to do it is if ( c & 0x80 ) if ( c & 0x40 ) /* ops for Group 1 */ else /* ops for Group 2 */ else /* ops for Group 3 */ But this uses more than one `&' operation, which may as much as double the decision time (although the optimizer may just surprise you). I prefer your way. However, you seem to believe that the two significant bits can be something other than `11', `10', `01', and `00' (note the impossible-to-reach printf()). That is, after the cases for FMASK and REPMASK, you should have only the default as the case for Group 3 (although the optimizer may just surprise me). --Blair "*i = i[0];"