binary constants (??)
    Raymond Chen 
    raymond at math.berkeley.edu
       
    Sun Nov 19 07:57:35 AEST 1989
    
    
  
/* 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 at math.berkeley.edu
    
    
More information about the Comp.lang.c
mailing list