Path: utzoo!yunexus!ists!jarvis.csri.toronto.edu!mailrus!iuvax!cica!tut.cis.ohio-state.edu!ucbvax!agate!usenet From: raymond@math.berkeley.edu (Raymond Chen) Newsgroups: comp.lang.c Subject: Re: binary constants (??) Keywords: macro, constant, binary Message-ID: <1989Nov18.205735.11004@agate.berkeley.edu> Date: 18 Nov 89 20:57:35 GMT Article-I.D.: agate.1989Nov18.205735.11004 References: <305@frf.omron.co.jp> <602@chem.ucsd.EDU> Sender: usenet@agate.berkeley.edu (USENET Administrator;;;;ZU44) Reply-To: raymond@math.berkeley.edu (Raymond Chen) Organization: U.C. Berkeley Lines: 43 In-reply-to: tps@chem.ucsd.edu (Tom Stockfisch) /* Disgusting macro alert! */ #define BIT1(x) (0 x #define BIT2(x) ((0 x #define BIT3(x) (((0 x /* ... */ #define BIT6(x) ((((((0 x #define O *2) #define I *2 + 1) main() { printf("%x", BIT6(I O I O I O)); /* the 6-bit number 101010 */ } ----- alternately ----- #define OOOO *16) #define OOOI *16+1) #define OOIO *16+2) /* ... */ #define IIII *16+15) #define BIT4(x) (0 x #define BIT8(x) ((0 x /* ... */ #define BIT16(x) ((((0 x main() { printf("%x", BIT16(OOOO OIOI IOIO OIIO)); /* the 16-bit number 0000 0101 1010 0110 */ } /* Disclaimer: I don't use this! I just wrote it to see if it could be done. It would be curious to compare this against the original poster's macro which approaches the problem from a different angle. */ Raymond Chen (mathematician by training, hacker by choice) raymond@math.berkeley.edu