Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

poslib/bits.h File Reference

bitmask manipulation More...

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


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.

Definition in file bits.h.


Define 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:
a  The bitmask, a character array
b  Bit index in the bitmask
Returns:
Nonzero if the bit is, set, zero if not.

Definition at line 75 of file bits.h.

#define 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:
a  The bitmask, a character array
b  Bit index in the bitmask

Definition at line 51 of file bits.h.

#define 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:
a  The bitmask, a character array
b  Bit index in the bitmask

Definition at line 42 of file bits.h.

#define bitsetval a,
b,
 )     ( (c) ? bitset(a, b) : 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:
a  The bitmask, a character array
b  Bit index in the bitmask
c  Boolean value to set the bit to

Definition at line 63 of file bits.h.


Generated on Fri Dec 24 19:55:15 2004 for Poslib by doxygen 1.3.7