Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!elroy.jpl.nasa.gov!lll-winken!news.arc.nasa.gov!ucsd!hub.ucsb.edu!angst From: angst@cs.ucsb.edu (Hopelessly in love w/Donna Reed) Newsgroups: comp.lang.c Subject: Bit Masking Question Message-ID: <12191@hub.ucsb.edu> Date: 23 Jun 91 07:50:18 GMT Sender: news@hub.ucsb.edu Reply-To: angst@cs.ucsb.edu (Hopelessly in love w/Donna Reed) Organization: Funf auf def nach oben offenen Richterskala Lines: 43 This is not necessarily a C question, but since I'm programming it C, I can ask in that context. 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. Here's how I'm currently doing it: #define FMASK 0xC0 #define RMASK 0x80 int c; ... switch (c & FMASK) { case FMASK: Do stuff for group 1 ... case REPMASK: Do stuff for group 2 ... case 0x0: case 0x40: Do stuff for group 3 ... default: fprintf (stderr, "bad news!\n"); } 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 Thanks in advance for any help! "Let the fools have their tartar sauce." | Dave Stein - Mr. Burns | angst@cs.ucsb.edu | angst%cs@ucsbuxa.bitnet