Xref: utzoo comp.lang.c:5527 comp.lang.c++:583 Path: utzoo!utgpu!water!watmath!watcgl!kdmoen From: kdmoen@watcgl.waterloo.edu (Doug Moen) Newsgroups: comp.lang.c,comp.lang.c++ Subject: Bitmap constants in C code (Re: Binary integer literals) Summary: you can do it with cpp Keywords: binary, integer, literal Message-ID: <2680@watcgl.waterloo.edu> Date: 11 Dec 87 22:46:52 GMT References: <2752@super.upenn.edu> Reply-To: kdmoen@watcgl.waterloo.edu (Doug Moen) Organization: U. of Waterloo, Ontario Lines: 56 george@hyper.lap.upenn.edu (George Zipperlen) writes: >static unsigned short CursorPattern[16] = { > 0xff00, /* 1111111100000000, */ > 0x8200, /* 1000001000000000, */ > 0x8400, /* 1000010000000000, */ > 0x8200, /* 1000001000000000, */ > 0x8100, /* 1000000100000000, */ > 0xa080, /* 1010000010000000, */ > 0xd040, /* 1101000001000000, */ > 0x8880, /* 1000100010000000, */ > 0x0500, /* 0000010100000000, */ > 0x0200, /* 0000001000000000, */ >What I would like to be able to do is to declare binary constants in some >form like (just a suggestion): > 0b#01000100 George wants to type in the bitmap pattern directly, without being forced to translate it into octal or hexadecimal. Here is a way to do this in ANSI C (no language extensions necessary): #define A +128 #define B +64 #define C +32 #define D +16 #define E +8 #define F +4 #define G +2 #define H +1 #define _ static unsigned char CursorPattern[32] = { A B C D E F G H,_ _ _ _ _ _ _ _, A _ _ _ _ _ G _,_ _ _ _ _ _ _ _, A _ _ _ _ F _ _,_ _ _ _ _ _ _ _, A _ _ _ _ _ G _,_ _ _ _ _ _ _ _, A _ _ _ _ _ _ H,_ _ _ _ _ _ _ _, A _ C _ _ _ _ _,A _ _ _ _ _ _ _, A B _ D _ _ _ _,_ B _ _ _ _ _ _, A _ _ _ E _ _ _,A _ _ _ _ _ _ _, _ _ _ _ _ F _ H,_ _ _ _ _ _ _ _, _ _ _ _ _ _ G _,_ _ _ _ _ _ _ _, ... Personally, I find this easier to read than binary integer literals, although its slightly more painful to type in. Note that the macros given above make use of unary +. It should not be difficult to come up with a similar set of macros that work in "real" (pre-ansi) C. -- Doug Moen University of Waterloo Computer Graphics Lab UUCP: {ihnp4,watmath}!watcgl!kdmoen INTERNET: kdmoen@cgl.waterloo.edu