> Henrik Nordstrom wrote:
> [Charset iso-8859-1 unsupported, filtering to ASCII...]
> > Moshe Zadka wrote:
> >
> > > OK, I want the first and fourth bit of a byte (cause the flags
> > > there matter to me, say) x&0x9 can be used, but x&0b1001 seems a
> > > bit clearer.
> >
> > I prefer having flags defined..
> >
> > /* Some hypotetical flags for a device called RTB */
> > #define RTB_FLAG_AAB (1<<0)
> > #define RTB_FLAG_ON_OFF (1<<1)
> > #define RTB_FLAG_AAC (1<<2)
> > #define RTB_FLAG_CCB (1<<3)
> >
> > And then compose the "binary" value using the flag names
> > ZAP_FLAG_AAB | ZAP_FLAG_CCB
> >
> > It is quite a bit more to write, but a lot easier to read a few weeks
> > later.
>
> They make code happier:
>
> /* Set */ thing |= RTB_FLAG_ON_OFF;
> /* Reset */ thing &= ~RTB_FLAG_ON_OFF;
> /* Toggle */ thing ^= RTB_FLAG_ON_OFF;
> /* Test */ if (thing & RTB_FLAG_ON_OFF) ...
>
>
> Macros to do this are obvious, and offer even more readability.
>
> Masks are left as an exercise for the reader.
>
> > I use decimal, octal and hex when writing numbers, using the base that
> > the number was originally written/specified.
>
> Sounds like we went to the same school :) Makes driver code almost
> readable. Nothing is more maddening than having a spec in octal,
> and discovering that some @#$@ coded it in hex and invented new mnemonics.
Here, here!
"What" code is doing is the easy stuff.
"Why" is horse of a different petard or a gord ox or something like that. It can
be the cause of an existential crisis depending on "who" is next to you holding
a large axe muttering something about whether sharp or dull is better.
david
--
David Ross
[EMAIL PROTECTED]
Toad Technologies
"I'll be good! I will, I will !"