ASN1C C/C++ Common Runtime  ASN1C v7.7.x
Macros | Functions
Bit String Functions

Macros

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

Functions

OSUINT32 rtxGetBitCount (OSUINT32 value)
 
int rtxSetBit (OSOCTET *pBits, OSSIZE numbits, OSSIZE bitIndex)
 
OSUINT32 rtxSetBitFlags (OSUINT32 flags, OSUINT32 mask, OSBOOL action)
 
int rtxClearBit (OSOCTET *pBits, OSSIZE numbits, OSSIZE bitIndex)
 
OSBOOL rtxTestBit (const OSOCTET *pBits, OSSIZE numbits, OSSIZE bitIndex)
 
OSSIZE rtxLastBitSet (const OSOCTET *pBits, OSSIZE numbits)
 
int rtxCheckBitBounds (OSCTXT *pctxt, OSOCTET **ppBits, OSSIZE *pNumocts, OSSIZE minRequiredBits, OSSIZE preferredLimitBits)
 
int rtxZeroUnusedBits (OSOCTET *pBits, OSSIZE numbits)
 
int rtxCheckUnusedBitsZero (const OSOCTET *pBits, OSSIZE numbits)
 

Detailed Description

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

Macro Definition Documentation

◆ OSRTBYTEARRAYSIZE

#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

◆ rtxCheckBitBounds()

int rtxCheckBitBounds ( OSCTXT pctxt,
OSOCTET **  ppBits,
OSSIZE *  pNumocts,
OSSIZE  minRequiredBits,
OSSIZE  preferredLimitBits 
)

Check whether the given bit string is large enough, and expand it if necessary.

Parameters
pctxtThe context to use should memory need to be allocated.
ppBits*ppBits is a pointer to the bit string, or NULL if one has not been created. If the string is expanded, *ppBits receives a pointer to the new bit string.
pNumoctspNumocts points to the current size of the bit string in octets. If the bit string is expanded, *pNumocts receives the new size.
minRequiredBitsThe minimum number of bits needed in the bit string. On return, pBits will point to a bit string with at least this many bits.
preferredLimitBitsThe number of bits over which we prefer not to go. If nonzero, no more bytes will be allocated than necessary for this many bits, unless explicitly required by minRequiredBits.
Returns
If successful, 0. Otherwise, an error code.

◆ rtxCheckUnusedBitsZero()

int rtxCheckUnusedBitsZero ( const OSOCTET *  pBits,
OSSIZE  numbits 
)

This function checks to see if unused bits at the end of the given bit string are zero.

Parameters
pBitsPointer to the octets of the bit string.
numbitsThe number of bits in the bit string.
Returns
Zero if the operation is successful, or a negative status code if the operation fails. RTERR_INVBINS will be returned if bits at end are not zero.

◆ rtxClearBit()

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

This function clears the specified zero-counted bit in the bit string.

Parameters
pBitsPointer to octets of bit string.
numbitsNumber of bits in the bit string.
bitIndexIndex 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 the bit. If bit was previously set, the return value is positive. If bit was not previously set, the return value is zero. Otherwise, return value is an error code:
  • RTERR_OUTOFBND = bitIndex is out of bounds

◆ rtxGetBitCount()

OSUINT32 rtxGetBitCount ( OSUINT32  value)

This function returns the minimum size of the bit field required to hold the given integer value.

Parameters
valueInteger value
Returns
Minimum size of the the field in bits required to hold value.

◆ rtxLastBitSet()

OSSIZE rtxLastBitSet ( const OSOCTET *  pBits,
OSSIZE  numbits 
)

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

Parameters
pBitsPointer to the octets of the bit string.
numbitsThe number of bits in the bit string.
Returns
Index of the last bit set in the bit string. OSNULLINDEX if no bit is set.

◆ rtxSetBit()

int rtxSetBit ( OSOCTET *  pBits,
OSSIZE  numbits,
OSSIZE  bitIndex 
)

This function sets the specified zero-counted bit in the bit string.

Parameters
pBitsPointer to octets of bit string.
numbitsNumber of bits in the bit string.
bitIndexIndex 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 the bit. If bit was previously set, the return value is positive. If bit was not previously set, the return value is zero. Otherwise, return value is an error code:
  • RTERR_OUTOFBND = bitIndex is out of bounds

◆ rtxSetBitFlags()

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
flagsFlags to which mask will be applied.
maskMask with one or more bits set that will be applied to pBitMask.
actionBoolean action indicating if bits in flags should be set (TRUE) or cleared (FALSE).
Returns
Updated flags after mask is applied.

◆ rtxTestBit()

OSBOOL rtxTestBit ( const OSOCTET *  pBits,
OSSIZE  numbits,
OSSIZE  bitIndex 
)

This function tests the specified zero-counted bit in the bit string.

Parameters
pBitsPointer to octets of bit string.
numbitsNumber of bits in the bit string.
bitIndexIndex 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.

◆ rtxZeroUnusedBits()

int rtxZeroUnusedBits ( OSOCTET *  pBits,
OSSIZE  numbits 
)

This function zeros unused bits at the end of the given bit string.

Parameters
pBitsPointer to the octets of the bit string.
numbitsThe number of bits in the bit string.
Returns
Zero if the operation is successful, or a negative status code if the operation fails.