fsfw/src/fsfw/globalfunctions/bitutility.cpp
Robin Mueller 6d5eb5b387
Op Divider and bitutility updates
- 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`
2021-11-10 18:48:02 +01:00

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;
}