Dibbler - a portable DHCPv6  1.0.2RC1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
bits.h File Reference

bitmask manipulation More...

+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define bitisset(a, b)   ( (a)[b / 8] & (1 << (7 - (b % 8))) )
 checks whether a bit is set
#define bitsetval(a, b, c)   ( (c) ? poslib_bitset(a, b) : poslib_bitreset(a, b) )
 sets the value of a bit in the bitmask
#define poslib_bitreset(a, b)   ( (a)[b / 8] &= ~(1 << (7 - (b % 8))) )
 reset a bit in the bitmask
#define poslib_bitset(a, b)   ( (a)[b / 8] |= 1 << (7 - (b % 8)) )
 set a bit in the bitmask

Detailed Description

bitmask manipulation

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.

Macro Definition Documentation

#define bitisset (   a,
 
)    ( (a)[b / 8] & (1 << (7 - (b % 8))) )

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!

Parameters
aThe bitmask, a character array
bBit index in the bitmask
Returns
Nonzero if the bit is, set, zero if not.
#define bitsetval (   a,
  b,
 
)    ( (c) ? poslib_bitset(a, b) : poslib_bitreset(a, b) )

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)).

Parameters
aThe bitmask, a character array
bBit index in the bitmask
cBoolean value to set the bit to
#define poslib_bitreset (   a,
 
)    ( (a)[b / 8] &= ~(1 << (7 - (b % 8))) )

reset a bit in the bitmask

Resets the bit value for the given bit in the bitmask.

Parameters
aThe bitmask, a character array
bBit index in the bitmask
#define poslib_bitset (   a,
 
)    ( (a)[b / 8] |= 1 << (7 - (b % 8)) )

set a bit in the bitmask

Sets the bit value for the given bit in the bitmask.

Parameters
aThe bitmask, a character array
bBit index in the bitmask