Dataflow Runtime API  3.1.1.0
Static Public Member Functions | List of all members
imt::base::core::util::BitUtil Class Reference

Bit Utility class pure static class. More...

#include <Imt.Base.Core.Util/BitUtil.h>

Static Public Member Functions

template<uint8_t Bit, typename T >
static bool isBitSet (T data)
 Check if a single bit in a data value is set. More...
 
template<typename T >
static bool isBitSet (T data, uint8_t bit)
 Check if a single bit in a data value is set. More...
 
template<uint8_t Bit, typename T >
static void setBit (T &data)
 Set one bit. More...
 
template<typename T >
static void setBit (T &data, uint8_t bit)
 Set one bit. More...
 
template<uint8_t Bit, typename T >
static void clearBit (T &data)
 Clear one bit. More...
 
template<typename T >
static void clearBit (T &data, uint8_t bit)
 Clear one bit. More...
 
template<unsigned Mask, typename T >
static T filterBits (T data)
 Filter some bits out of a data value. More...
 
template<unsigned Mask, unsigned CheckValue, typename T >
static bool matchBits (T data)
 Check if a value is equal to another one, but only some bits have an influence on the result. More...
 
template<unsigned Mask, typename T >
static void setBits (T &data, T value)
 Set some bits. More...
 
template<unsigned Mask, typename T >
static void clearBits (T &data, T value)
 Clear some bits. More...
 
template<unsigned Mask, typename T >
static void changeBits (T &data, T value)
 Change some bits. More...
 
template<uint8_t Bit, typename T >
static void changeBit (T &data, bool value)
 Set or clear a single bit in a data value. More...
 
template<typename T >
static void changeBit (T &data, uint8_t bit, bool value)
 Set or clear a single bit in a data value. More...
 

Detailed Description

Bit Utility class pure static class.

Member Function Documentation

◆ changeBit() [1/2]

template<uint8_t Bit, typename T >
static void imt::base::core::util::BitUtil::changeBit ( T &  data,
bool  value 
)
inlinestatic

Set or clear a single bit in a data value.

Template Parameters
BitThe bit to change. The value of Bit will be checked at compile time.
TThe type of the value. Usually this type will be automatically detected by the compiler.
Parameters
dataThe data in which the bit will be changed.
valueIf true the bit will be set after this operation, else cleared.

◆ changeBit() [2/2]

template<typename T >
static void imt::base::core::util::BitUtil::changeBit ( T &  data,
uint8_t  bit,
bool  value 
)
inlinestatic

Set or clear a single bit in a data value.

Template Parameters
TThe type of the value. Usualy this type will be automatically detected by the compiler.
Parameters
dataThe data in which the bit will be changed.
bitThe bit to change.
valueIf true the bit will be set after this operation, else cleared.

◆ changeBits()

template<unsigned Mask, typename T >
static void imt::base::core::util::BitUtil::changeBits ( T &  data,
value 
)
inlinestatic

Change some bits.

The bits which may change can be selected with a mask. The bits will be cleared and then set.

Template Parameters
MaskThe bits which possibly will be changed.
TType on which to operate.
Parameters
dataThe data in which the bits may will be changed.
valueThe value that changes the bits.

◆ clearBit() [1/2]

template<uint8_t Bit, typename T >
static void imt::base::core::util::BitUtil::clearBit ( T &  data)
inlinestatic

Clear one bit.

Template Parameters
BitThe zero based index of the bit. The value of Bit will be checked at compile time.
TType on which to operate.
Parameters
dataThe data in which the bit may will be changed.

◆ clearBit() [2/2]

template<typename T >
static void imt::base::core::util::BitUtil::clearBit ( T &  data,
uint8_t  bit 
)
inlinestatic

Clear one bit.

Template Parameters
TType on which to operate.
Parameters
dataThe data in which the bit may will be changed.
bitThe zero based index of the bit.

◆ clearBits()

template<unsigned Mask, typename T >
static void imt::base::core::util::BitUtil::clearBits ( T &  data,
value 
)
inlinestatic

Clear some bits.

The bits which may get cleared can be selected with a mask. Only the bits which are in the mask and in the value will be cleared. Example: clearBits<0x03, uint8_t>(v, 0x12) -> Clears only bit 1. After this operation, only bit 1 of v will be cleared. All other bits will not change.

Template Parameters
TType on which to operate.
MaskThe bits which possibly will be changed.
Parameters
dataThe data in which the bits may will be changed.
valueThe value that changes the bits.

◆ filterBits()

template<unsigned Mask, typename T >
static T imt::base::core::util::BitUtil::filterBits ( data)
inlinestatic

Filter some bits out of a data value.

Template Parameters
TType on which to operate. This type must support boolean AND operation.
MaskThe bits which have an influence on the result. The bits of data are left in their original state, if the appropriate bit in Mask is set too. This argument is of type unsigned because of the IAR/R8C compiler. Otherwise this code would not compile!
Parameters
dataData value.
Returns
Filtered bits.

◆ isBitSet() [1/2]

template<uint8_t Bit, typename T >
static bool imt::base::core::util::BitUtil::isBitSet ( data)
inlinestatic

Check if a single bit in a data value is set.

Template Parameters
BitThe zero based index of the bit. The value of Bit will be checked at compile time.
TThe type of the value. Usually this type will be automatically detected by the compiler.
Parameters
dataThe data value in which the bit should be checked.
Returns
True if the bit is set, else false.

◆ isBitSet() [2/2]

template<typename T >
static bool imt::base::core::util::BitUtil::isBitSet ( data,
uint8_t  bit 
)
inlinestatic

Check if a single bit in a data value is set.

Template Parameters
TThe type of the value.
Parameters
dataThe data value in which the bit should be checked.
bitThe zero based index of the bit.
Returns
True if the bit is set, else false.

◆ matchBits()

template<unsigned Mask, unsigned CheckValue, typename T >
static bool imt::base::core::util::BitUtil::matchBits ( data)
inlinestatic

Check if a value is equal to another one, but only some bits have an influence on the result.

Template Parameters
MaskThe bits which have an influence on the result. This argument is of type unsigned because of the IAR/R8C compiler. Otherwise this code would not compile!
CheckValueThe value that should result when comparing Value. CheckValue must not contain any bits which are not in the mask. This argument is of type unsigned because of the IAR/R8C compiler. Otherwise this code would not compile!
TType on which to operate.
Parameters
dataData masked with Mask.
Returns
True if bits match.

◆ setBit() [1/2]

template<uint8_t Bit, typename T >
static void imt::base::core::util::BitUtil::setBit ( T &  data)
inlinestatic

Set one bit.

Template Parameters
BitThe zero based index of the bit. The value of Bit will be checked at compile time.
TType on which to operate.
Parameters
dataThe data in which the bit may will be changed.

◆ setBit() [2/2]

template<typename T >
static void imt::base::core::util::BitUtil::setBit ( T &  data,
uint8_t  bit 
)
inlinestatic

Set one bit.

Template Parameters
TType on which to operate.
Parameters
dataThe data in which the bit may will be changed.
bitThe zero based index of the bit.

◆ setBits()

template<unsigned Mask, typename T >
static void imt::base::core::util::BitUtil::setBits ( T &  data,
value 
)
inlinestatic

Set some bits.

The bits which may get set can be selected with a mask. Only the bits which are in the mask and in the value will be set. Example: setBits<0x03, uint8_t>(v, 0x12) -> Sets only bit 1. After this operation, only bit 1 of v will be set. All other bits will not change.

Template Parameters
MaskThe bits which possibly will be changed.
TType on which to operate.
Parameters
dataThe data in which the bits may will be changed.
valueThe value that changes the bits.

The documentation for this class was generated from the following file: