Bit String Functions

Defines

#define OSRTBYTEARRAYSIZE(numbits)   (((numbits-1)/8)+1)

Functions

int rtxSetBit (OSOCTET *pBits, OSUINT32 numbits, OSUINT32 bitIndex)
OSUINT32 rtxSetBitFlags (OSUINT32 flags, OSUINT32 mask, OSBOOL action)
int rtxClearBit (OSOCTET *pBits, OSUINT32 numbits, OSUINT32 bitIndex)
OSBOOL rtxTestBit (const OSOCTET *pBits, OSUINT32 numbits, OSUINT32 bitIndex)

Detailed Description

Bit string functions allow bits to be set, cleared, or tested in arbitrarily sized byte arrays.


Define Documentation

#define OSRTBYTEARRAYSIZE ( numbits   )     (((numbits-1)/8)+1)

This macro is used to calculate the byte array size required to hold the given number of bits.


Function Documentation

int rtxClearBit ( OSOCTET *  pBits,
OSUINT32  numbits,
OSUINT32  bitIndex 
)

This function clears the specified bit in the bit string.

Parameters:
pBits Pointer to octets of bit string.
numbits Number of bits in the bit string.
bitIndex Index of bit to be cleared. The bit with index 0 is a most significant bit in the octet with index 0.
Returns:
If successful, returns the previous state of bit. If bit was set the return value is positive, if bit was not set the return value is zero. Otherwise, return value is an error code:
  • RTERR_OUTOFBND = bitIndex is out of bounds
int rtxSetBit ( OSOCTET *  pBits,
OSUINT32  numbits,
OSUINT32  bitIndex 
)

This function sets the specified bit in the bit string.

Parameters:
pBits Pointer to octets of bit string.
numbits Number of bits in the bit string.
bitIndex Index of bit to be set. The bit with index 0 is a most significant bit in the octet with index 0.
Returns:
If successful, returns the previous state of bit. If bit was set the return value is positive, if bit was not set the return value is zero. Otherwise, return value is an error code:
  • RTERR_OUTOFBND = bitIndex is out of bounds
OSUINT32 rtxSetBitFlags ( OSUINT32  flags,
OSUINT32  mask,
OSBOOL  action 
)

This function sets one or more bits to TRUE or FALSE in a 32-bit unsigned bit flag set.

Parameters:
flags Flags to which mask will be applied.
mask Mask with one or more bits set that will be applied to pBitMask.
action Boolean action indicating if bits in flags should be set (TRUE) or cleared (FALSE).
Returns:
Updated flags after mask is applied.
OSBOOL rtxTestBit ( const OSOCTET *  pBits,
OSUINT32  numbits,
OSUINT32  bitIndex 
)

This function tests the specified bit in the bit string.

Parameters:
pBits Pointer to octets of bit string.
numbits Number of bits in the bit string.
bitIndex Index of bit to be tested. The bit with index 0 is a most significant bit in the octet with index 0.
Returns:
True if bit set or false if not set or array index is beyond range of number of bits in the string.