Bit String Functions

Defines

#define OSRTBYTEARRAYSIZE(numbits)   ((numbits+7)/8)

Functions

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

Detailed Description

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


Define Documentation

#define OSRTBYTEARRAYSIZE ( numbits   )     ((numbits+7)/8)

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


Function Documentation

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

This function clears the specified zero-counted 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
OSUINT32 rtxLastBitSet ( const OSOCTET *  pBits,
size_t  numbits 
)

This function returns the zero-counted index of the last bit set in a bit string.

Parameters:
pBits Pointer to the octets of the bit string.
numbits The number of bits in the bit string.
Returns:
Index of the last bit set in the bit string.
int rtxSetBit ( OSOCTET *  pBits,
size_t  numbits,
size_t  bitIndex 
)

This function sets the specified zero-counted 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,
size_t  numbits,
size_t  bitIndex 
)

This function tests the specified zero-counted 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.