Bit manipulation utilities.
More...
|
| file | utils.h |
| | Bit manipulation utilities.
|
| |
Bit manipulation utilities.
- Note
- All functions are kept as small as possible allowing inlining.
◆ bitSet()
template<typename T >
| void Sensors::bitSet |
( |
T & |
value, |
|
|
uint8_t |
bit |
|
) |
| |
|
inline |
Sets the bit in the given value to 1.
- Template Parameters
-
| T | Data type of the value to operate on. |
- Parameters
-
| value | Memory location of the value where the bit should be set. |
| bit | Bit position within the value. |
◆ bitClear()
template<typename T >
| void Sensors::bitClear |
( |
T & |
value, |
|
|
uint8_t |
bit |
|
) |
| |
|
inline |
Sets the bit in the given value to 0.
- Template Parameters
-
| T | Data type of the value to operate on. |
- Parameters
-
| value | Memory location of the value where the bit should be cleared. |
| bit | Bit position within the value. |
◆ bitFlip()
template<typename T >
| void Sensors::bitFlip |
( |
T & |
value, |
|
|
uint8_t |
bit |
|
) |
| |
|
inline |
Flips the bit in the given value.
- Template Parameters
-
| T | Data type of the value to operate on. |
- Parameters
-
| value | Memory location of the value where bit should be flipped. |
| bit | Bit position within the value. |
◆ bitRead()
template<typename T >
| bool Sensors::bitRead |
( |
T & |
value, |
|
|
uint8_t |
bit |
|
) |
| |
|
inline |
Returns the bit in the given value.
- Template Parameters
-
| T | Data type of the value to operate on. |
- Parameters
-
| value | Memory location of the value where the bit should be read. |
| bit | Bit position within the value. |
- Returns
- Specified bit in the given
value.
◆ bitWrite()
template<typename T >
| void Sensors::bitWrite |
( |
T & |
value, |
|
|
uint8_t |
bit, |
|
|
bool |
bitValue |
|
) |
| |
|
inline |
Writes the bit in the given value.
- Template Parameters
-
| T | Data type of the value to operate on. |
- Parameters
-
| value | Memory location of the value where the bit should be written. |
| bit | Number of the bit to write. |
| bitValue | Value to write into bit position. |
◆ byteReverse()
| uint8_t Sensors::byteReverse |
( |
uint8_t |
x | ) |
|
|
inline |
Returns the byte x in reversed bit order.
- Parameters
-
- Returns
- Byte with bits reversed.
◆ nibbleReverse()
| uint8_t Sensors::nibbleReverse |
( |
uint8_t |
x | ) |
|
|
inline |
Returns the byte x in reversed bit order (nibble wise).
- Parameters
-
- Returns
- Byte with bits nibble wise reversed.
◆ highNibble()
| uint8_t Sensors::highNibble |
( |
uint8_t |
x | ) |
|
|
inline |
Returns the byte's x high nibble.
- Parameters
-
- Returns
- High nibble of byte
x.
◆ lowNibble()
| uint8_t Sensors::lowNibble |
( |
uint8_t |
x | ) |
|
|
inline |
Returns the byte's x low nibble.
- Parameters
-
- Returns
- Low nibble of byte
x.
◆ word()
| uint16_t Sensors::word |
( |
uint8_t |
highByte, |
|
|
uint8_t |
lowByte |
|
) |
| |
|
inline |
Converts two bytes to a word.
- Parameters
-
| highByte | The leftmost byte of the word. |
| lowByte | The rightmost byte of the word. |
- Returns
- Word from
highByte and lowByte.
◆ parity()
| bool Sensors::parity |
( |
int |
x | ) |
|
|
inline |
Returns the even parity for the byte x.
Even parity: Number of set bits modulo 2.
- Parameters
-
- Returns
- Even parity for the byte
x.
◆ min()
template<typename T >
| T Sensors::min |
( |
T |
a, |
|
|
T |
b |
|
) |
| |
|
inline |
Returns the minimum of the two values a and b.
- Template Parameters
-
| T | Data type of the values to operate on. |
- Parameters
-
| a | First value. |
| b | Second value. |
- Returns
- Minimum of the two values
a and b.
◆ max()
template<typename T >
| T Sensors::max |
( |
T |
a, |
|
|
T |
b |
|
) |
| |
|
inline |
Returns the maximum of the two values a and b.
- Template Parameters
-
| T | Data type of the values to operate on. |
- Parameters
-
| a | First value. |
| b | Second value. |
- Returns
- Maximum of the two values
a and b.