Bit Utility class pure static class.
More...
#include <Imt.Base.Core.Util/BitUtil.h>
|
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...
|
|
Bit Utility class pure static class.
◆ 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
-
Bit | The bit to change. The value of Bit will be checked at compile time. |
T | The type of the value. Usually this type will be automatically detected by the compiler. |
- Parameters
-
data | The data in which the bit will be changed. |
value | If 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
-
T | The type of the value. Usualy this type will be automatically detected by the compiler. |
- Parameters
-
data | The data in which the bit will be changed. |
bit | The bit to change. |
value | If 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, |
|
|
T |
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
-
Mask | The bits which possibly will be changed. |
T | Type on which to operate. |
- Parameters
-
data | The data in which the bits may will be changed. |
value | The 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
-
Bit | The zero based index of the bit. The value of Bit will be checked at compile time. |
T | Type on which to operate. |
- Parameters
-
data | The 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
-
T | Type on which to operate. |
- Parameters
-
data | The data in which the bit may will be changed. |
bit | The zero based index of the bit. |
◆ clearBits()
template<unsigned Mask, typename T >
static void imt::base::core::util::BitUtil::clearBits |
( |
T & |
data, |
|
|
T |
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
-
T | Type on which to operate. |
Mask | The bits which possibly will be changed. |
- Parameters
-
data | The data in which the bits may will be changed. |
value | The value that changes the bits. |
◆ filterBits()
template<unsigned Mask, typename T >
static T imt::base::core::util::BitUtil::filterBits |
( |
T |
data | ) |
|
|
inlinestatic |
Filter some bits out of a data value.
- Template Parameters
-
T | Type on which to operate. This type must support boolean AND operation. |
Mask | The 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
-
- Returns
- Filtered bits.
◆ isBitSet() [1/2]
template<uint8_t Bit, typename T >
static bool imt::base::core::util::BitUtil::isBitSet |
( |
T |
data | ) |
|
|
inlinestatic |
Check if a single bit in a data value is set.
- Template Parameters
-
Bit | The zero based index of the bit. The value of Bit will be checked at compile time. |
T | The type of the value. Usually this type will be automatically detected by the compiler. |
- Parameters
-
data | The 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 |
( |
T |
data, |
|
|
uint8_t |
bit |
|
) |
| |
|
inlinestatic |
Check if a single bit in a data value is set.
- Template Parameters
-
- Parameters
-
data | The data value in which the bit should be checked. |
bit | The 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 |
( |
T |
data | ) |
|
|
inlinestatic |
Check if a value is equal to another one, but only some bits have an influence on the result.
- Template Parameters
-
Mask | The 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! |
CheckValue | The 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! |
T | Type on which to operate. |
- Parameters
-
data | Data 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
-
Bit | The zero based index of the bit. The value of Bit will be checked at compile time. |
T | Type on which to operate. |
- Parameters
-
data | The 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
-
T | Type on which to operate. |
- Parameters
-
data | The data in which the bit may will be changed. |
bit | The zero based index of the bit. |
◆ setBits()
template<unsigned Mask, typename T >
static void imt::base::core::util::BitUtil::setBits |
( |
T & |
data, |
|
|
T |
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
-
Mask | The bits which possibly will be changed. |
T | Type on which to operate. |
- Parameters
-
data | The data in which the bits may will be changed. |
value | The value that changes the bits. |
The documentation for this class was generated from the following file:
- D:/_Work/10/s/Imt.Base/Imt.Base.Core.Util/BitUtil.h