bitops.h

General-purpose bit and bit field manipulation macros.

Summary
bitops.hGeneral-purpose bit and bit field manipulation macros.
Macros
BITOPS_1The expression the bitops macros will use to represent an integer with the least significant bit set to one (1) and the other bits set to zero (0).
BVMaps a bit number to an integer value with (only) the corresponding bit set to 1.
BITMASKMaps a mask size to an integer bit mask with the corresponding number of bits set to 1.
BITMASK_ATMaps a mask size and offset to an integer bit mask with the corresponding number of bits set to 1, at the specified offset.
BITMASK_NOT_ATMaps a mask size and offset to an inverted integer bit mask with the corresponding number of bits set to 0, at the specified offset.
BITSTATESMaps a number of bits to the number of possible states of a value with that number of bits.
BITMAXUtility macro that maps a number of bits to the maximum value of an unsigned integer with that number of bits.
GET_BITFIELDMaps a field size and an arbitary integer to an integer containing the bitfield with the specified size, from the least significant bits of the arbitrary integer.
GET_BITFIELD_ATMaps a field size, a field offset and an arbitary integer to an integer containing the bitfield with the specified size at the specified offset in the arbitrary integer.
MAKE_BITFIELD_ATMaps a field size, a field offset and an arbitary integer to an integer that has a bitfield with the specified size at the specified offset, containing bits from the arbitrary integer.
CLEAR_BITFIELD_ATMaps a field size, a field offset and an arbitary integer to an integer where the bitfield with the specified size at the specified offset in the arbitrary integer has been cleared.
SET_BITFIELD_ATMaps a field size, a field offset and two arbitary integers to an integer that has a bitfield with the specified size at the specified offset, containing bits from the second arbitrary integer, while the remaining bits are equal to the corresponding bits in the first arbitrary integer.

Macros

BITOPS_1

The expression the bitops macros will use to represent an integer with the least significant bit set to one (1) and the other bits set to zero (0).  Configuration macro.

Default value: 1U

BV

Maps a bit number to an integer value with (only) the corresponding bit set to 1.  Function-like macro.

Parameters

NA bit number.  Should be in the range 0-7 for 8-bit values and 0-15 for 16-bit values.  Bit 0 is the least significant and bit 7/15 the most significant.

Returns

An integer value with (only) the specified bit set to one (1).

BITMASK

Maps a mask size to an integer bit mask with the corresponding number of bits set to 1.  Function-like macro.

Parameters

NA mask size.  Should be in the range 0-8 for 8-bit values and 0-16 for 16-bit values.

Returns

An integer value with only the N lowest-significance bits set to one (1).

BITMASK_AT

Maps a mask size and offset to an integer bit mask with the corresponding number of bits set to 1, at the specified offset.  Function-like macro.

Parameters

NA mask size.  Should be in the range 0-8 for 8-bit values and 0-16 for 16-bit values.
OA mask offset.  Should be less than or equal to (T - N), where T is the total number of bits in a value.

Returns

An integer value with only the N bits starting at bit number O set to one (1).

BITMASK_NOT_AT

Maps a mask size and offset to an inverted integer bit mask with the corresponding number of bits set to 0, at the specified offset.  Function-like macro.

Parameters

NA mask size.  Should be in the range 0-8 for 8-bit values and 0-16 for 16-bit values.
OA mask offset.  Should be less than or equal to (T - N), where T is the total number of bits in a value.

Returns

An integer value with only the N bits starting at bit number O set to zero (0).

BITSTATES

Maps a number of bits to the number of possible states of a value with that number of bits.  Alias of BV.  Function-like macro.

Parameters

NA number of bits.

Returns

The number of possible states of an N-bit value (i.e.  2^*N*).

BITMAX

Utility macro that maps a number of bits to the maximum value of an unsigned integer with that number of bits.  Alias of BITMASK.  Function-like macro.

Parameters

NA number of bits.

Returns

The maximum value of an *N*-bit unsigned integer (i.e.  2^*N*1).

GET_BITFIELD

Maps a field size and an arbitary integer to an integer containing the bitfield with the specified size, from the least significant bits of the arbitrary integer.  Function-like macro.

Parameters

SA field size.  Should be in the range 0-8 for 8-bit values and 0-16 for 16-bit values.
DAn arbitrary integer to get a bitfield from.

Returns

An integer value containing the S lowest-significance bits of D.  The remaining bits are set to zero (0).

GET_BITFIELD_AT

Maps a field size, a field offset and an arbitary integer to an integer containing the bitfield with the specified size at the specified offset in the arbitrary integer.  Function-like macro.

Parameters

SA field size.  Should be in the range 0-8 for 8-bit values and 0-16 for 16-bit values.
OA field offset.  Should be less than or equal to (T - S), where T is the total number of bits in a value.
DAn arbitrary integer to get an offset bitfield from.

Returns

An integer value containing the S bits starting at bit number O in D, shifted into the lowest-significance bits.  The remaining bits are set to zero (0).

MAKE_BITFIELD_AT

Maps a field size, a field offset and an arbitary integer to an integer that has a bitfield with the specified size at the specified offset, containing bits from the arbitrary integer.  Function-like macro.

Parameters

SA field size.  Should be in the range 0-8 for 8-bit values and 0-16 for 16-bit values.
OA field offset.  Should be less than or equal to (T - S), where T is the total number of bits in a value.
XAn arbitrary integer containing a bitfield value.

Returns

An integer value containing the S lowest-significance bits of X, shifted to offset O.  The remaining bits are set to zero (0).

CLEAR_BITFIELD_AT

Maps a field size, a field offset and an arbitary integer to an integer where the bitfield with the specified size at the specified offset in the arbitrary integer has been cleared.  Function-like macro.

Parameters

SA field size.  Should be in the range 0-8 for 8-bit values and 0-16 for 16-bit values.
OA field offset.  Should be less than or equal to (T - S), where T is the total number of bits in a value.
DAn arbitrary integer to clear a bitfield in.

Returns

An integer value where the S bits starting at bit number O are set to zero (0).  The remaining bits have the values they have in D.

SET_BITFIELD_AT

Maps a field size, a field offset and two arbitary integers to an integer that has a bitfield with the specified size at the specified offset, containing bits from the second arbitrary integer, while the remaining bits are equal to the corresponding bits in the first arbitrary integer.  Function-like macro.

Parameters

SA field size.  Should be in the range 0-8 for 8-bit values and 0-16 for 16-bit values.
OA field offset.  Should be less than or equal to (T - S), where T is the total number of bits in a value.
DAn arbitrary integer to set a bitfield in.
XAn arbitrary integer containing a bitfield value.

Returns

An integer value containing the S lowest-significance bits of X, shifted to offset O.  The remaining bits have the values they have in D.

Maps a bit number to an integer value with (only) the corresponding bit set to 1.
Maps a mask size to an integer bit mask with the corresponding number of bits set to 1.
Close