Path: utzoo!mnetor!uunet!husc6!cmcl2!yale!bunker!garys From: garys@bunker.UUCP (Gary M. Samuelson) Newsgroups: comp.lang.c Subject: Re: Bitmap constants in C code Message-ID: <3137@bunker.UUCP> Date: 23 Dec 87 20:08:52 GMT Organization: Bunker Ramo, an Olivetti Company, Shelton, CT Lines: 44 Keywords: binary, integer, literal In (belated) response to George Zipperlan and Doug Moen: George wanted to enter binary constants (e.g., 0b#01000100). Doug suggested some tricky defines: #define A +128 #define B +64 #define C +32 ... char pattern[] = { A _ C _ E _ F _, ... }; This allows binary constants in ANSI C. I applaud Doug's ingenuity, and suggest the following alternative: #define X )*2+1 #define _ )*2 #define b ((((((((0 /* For byte building */ #define w ((((((((((((((((0 /* For word building */ George's original problem (bit pattern for an arrow) is thus: static unsigned short CursorPattern[] = { w X X X X X X X X _ _ _ _ _ _ _ _, w X _ _ _ _ _ X _ _ _ _ _ _ _ _ _, w X _ _ _ _ X _ _ _ _ _ _ _ _ _ _, w X _ _ _ _ _ X _ _ _ _ _ _ _ _ _, w X _ _ _ _ _ _ X _ _ _ _ _ _ _ _, w X _ X _ _ _ _ _ X _ _ _ _ _ _ _, w X X _ X _ _ _ _ _ X _ _ _ _ _ _, w X _ _ _ X _ _ _ X _ _ _ _ _ _ _, w _ _ _ _ _ X _ X _ _ _ _ _ _ _ _, w _ _ _ _ _ _ X _ _ _ _ _ _ _ _ _ }; There are three improvements over Doug's solution: 1. Unary '+' is not required. 2. You don't have to remember which letter goes in which column. 3. It is just as easy to build any size of binary datum. Gary Samuelson Should I have saved those macros for the next obfuscated C contest?