Go to the source code of this file.
Defines |
|
#define | bitset(a, b) ( (a)[b / 8] |= 1 << (7 - (b % 8)) ) |
set a bit in the bitmask |
|
#define | bitreset(a, b) ( (a)[b / 8] &= ~(1 << (7 - (b % 8))) ) |
reset a bit in the bitmask |
|
#define | bitsetval(a, b, c) ( (c) ? bitset(a, b) : bitreset(a, b) ) |
sets the value of a bit in the bitmask |
|
#define | bitisset(a, b) ( (a)[b / 8] & (1 << (7 - (b % 8))) ) |
checks whether a bit is set |
This source file provides some macros to easily handle bit masks, which are basically just character arrays. These macros do not handle the creation of bitmasks, so you'll need to do that yourself. To create a bitmask for x bits, allocate a character array of (x + 7) / 8 bytes. And be sure to memset() it to reset all bits in one! Also note the first bitmap index is zero and the last one is x - 1.
Definition in file bits.h.
|
checks whether a bit is set This function checks whether a given bit in the bitmask is set. If the bit is set, the function returns nonzero. Note that it _might_ return 1, but that it usually doesn't so don't depend on that!
|
|
reset a bit in the bitmask Resets the bit value for the given bit in the bitmask.
|
|
set a bit in the bitmask Sets the bit value for the given bit in the bitmask.
|
|
sets the value of a bit in the bitmask Sets the value of a bit in the bitmask. If c is non-zero, the given bit is set, otherwise, the given bit is reset. This can come in handy if you want to do bitsetval(a, b, bitisset(c, d)).
|