[This was posted by Alan Watson back in 1996,
passing on a suggestion by Mark Brader.
Dik Winter believes that the original idea was due to Karl Heuer.]
For this purpose, probably the best thing is some creative use of macros.
(I wish I could remember who invented this little trick.) You can write
the 16-bit binary number 1100110011110000 as
B16( X X O O X X O O X X X X O O O O )
if you first define
#define X <<1)+1
#define O <<1)
/* the argument of B16 must be a total of 16 occurrences of
one or the other of the above two macros, effectively
expressing a number in binary */
#define B16(arg) (((((((((((((((((0 arg)
For visual purposes it may be even better to use _ as the name for the
zero-bit, rather than O; but there's a loss of portability then, since
the identifier _ is in the C implementation's name space and therefore
may be used for some purpose in some implementations. Another good
choice would be o, which suggests 0 without looking quite so much like it.
If you're using an unsigned type for the bitmap, as one normally should,
then cast the 0 to that type inside the definition of the macro B16.
back
about this FAQ list
about eskimo
search
feedback
copyright
Hosted by