atMETEO
An ATmega based weather station
Files | Functions

Bit manipulation utilities. More...

Collaboration diagram for Utilities:

Files

file  utils.h
 Bit manipulation utilities.
 

Functions

template<typename T >
void Sensors::bitSet (T &value, uint8_t bit)
 Sets the bit in the given value to 1. More...
 
template<typename T >
void Sensors::bitClear (T &value, uint8_t bit)
 Sets the bit in the given value to 0. More...
 
template<typename T >
void Sensors::bitFlip (T &value, uint8_t bit)
 Flips the bit in the given value. More...
 
template<typename T >
bool Sensors::bitRead (T &value, uint8_t bit)
 Returns the bit in the given value. More...
 
template<typename T >
void Sensors::bitWrite (T &value, uint8_t bit, bool bitValue)
 Writes the bit in the given value. More...
 
uint8_t Sensors::byteReverse (uint8_t x)
 Returns the byte x in reversed bit order. More...
 
uint8_t Sensors::nibbleReverse (uint8_t x)
 Returns the byte x in reversed bit order (nibble wise). More...
 
uint8_t Sensors::highNibble (uint8_t x)
 Returns the byte's x high nibble. More...
 
uint8_t Sensors::lowNibble (uint8_t x)
 Returns the byte's x low nibble. More...
 
uint16_t Sensors::word (uint8_t highByte, uint8_t lowByte)
 Converts two bytes to a word. More...
 
bool Sensors::parity (int x)
 Returns the even parity for the byte x. More...
 
template<typename T >
Sensors::min (T a, T b)
 Returns the minimum of the two values a and b. More...
 
template<typename T >
Sensors::max (T a, T b)
 Returns the maximum of the two values a and b. More...
 

Detailed Description

Bit manipulation utilities.

Note
All functions are kept as small as possible allowing inlining.

Function Documentation

◆ bitSet()

template<typename T >
void Sensors::bitSet ( T &  value,
uint8_t  bit 
)
inline

Sets the bit in the given value to 1.

Template Parameters
TData type of the value to operate on.
Parameters
valueMemory location of the value where the bit should be set.
bitBit 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
TData type of the value to operate on.
Parameters
valueMemory location of the value where the bit should be cleared.
bitBit 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
TData type of the value to operate on.
Parameters
valueMemory location of the value where bit should be flipped.
bitBit 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
TData type of the value to operate on.
Parameters
valueMemory location of the value where the bit should be read.
bitBit 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
TData type of the value to operate on.
Parameters
valueMemory location of the value where the bit should be written.
bitNumber of the bit to write.
bitValueValue to write into bit position.

◆ byteReverse()

uint8_t Sensors::byteReverse ( uint8_t  x)
inline

Returns the byte x in reversed bit order.

Parameters
xThe input byte.
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
xThe input byte.
Returns
Byte with bits nibble wise reversed.

◆ highNibble()

uint8_t Sensors::highNibble ( uint8_t  x)
inline

Returns the byte's x high nibble.

Parameters
xThe input byte.
Returns
High nibble of byte x.

◆ lowNibble()

uint8_t Sensors::lowNibble ( uint8_t  x)
inline

Returns the byte's x low nibble.

Parameters
xThe input byte.
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
highByteThe leftmost byte of the word.
lowByteThe 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
xThe input byte.
Returns
Even parity for the byte x.

◆ min()

template<typename T >
T Sensors::min ( a,
b 
)
inline

Returns the minimum of the two values a and b.

Template Parameters
TData type of the values to operate on.
Parameters
aFirst value.
bSecond value.
Returns
Minimum of the two values a and b.

◆ max()

template<typename T >
T Sensors::max ( a,
b 
)
inline

Returns the maximum of the two values a and b.

Template Parameters
TData type of the values to operate on.
Parameters
aFirst value.
bSecond value.
Returns
Maximum of the two values a and b.