"Jack Klein" <ja*******@spamcop.net> wrote:
You must have somehow missed this question (and its answer)
when you read the FAQ for this group, as you are supposed
to and surely did before you posted here:
20.8 How can I implement sets or arrays of bits?
The macros given in the FAQ:
#define BITMASK(b) (1 << ((b) % CHAR_BIT))
#define BITSLOT(b) ((b) / CHAR_BIT)
#define BITSET(a, b) ((a)[BITSLOT(b)] |= BITMASK(b))
#define BITTEST(a, b) ((a)[BITSLOT(b)] & BITMASK(b))
Seem to be missing a way to clear a bit?
#define BITCLEAR(a, b) ((a)[BITSLOT(b)] &= ~BITMASK(b))
May as well add a toggler too:
#define BITFLIP(a, b) ((a)[BITSLOT(b)] ^= BITMASK(b))
--
Simon.