Robin Mueller
6d5eb5b387
- Added unittests for `PeriodicOperationDivider` and the `bitutil` helpers - Some API changes: Removed redundant bit part, because these functions are already in a namespace - Some bugfixes for `PeriodicOperationDivider`
35 lines
856 B
C++
35 lines
856 B
C++
#include "fsfw/globalfunctions/bitutility.h"
|
|
|
|
void bitutil::set(uint8_t *byte, uint8_t position) {
|
|
if(position > 7) {
|
|
return;
|
|
}
|
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
|
*byte |= 1 << shiftNumber;
|
|
}
|
|
|
|
void bitutil::toggle(uint8_t *byte, uint8_t position) {
|
|
if(position > 7) {
|
|
return;
|
|
}
|
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
|
*byte ^= 1 << shiftNumber;
|
|
}
|
|
|
|
void bitutil::clear(uint8_t *byte, uint8_t position) {
|
|
if(position > 7) {
|
|
return;
|
|
}
|
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
|
*byte &= ~(1 << shiftNumber);
|
|
}
|
|
|
|
bool bitutil::get(const uint8_t *byte, uint8_t position, bool& bit) {
|
|
if(position > 7) {
|
|
return false;
|
|
}
|
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
|
bit = *byte & (1 << shiftNumber);
|
|
return true;
|
|
}
|