2021-07-13 20:22:54 +02:00
|
|
|
#include "fsfw/globalfunctions/bitutility.h"
|
2021-02-28 16:34:11 +01:00
|
|
|
|
|
|
|
void bitutil::bitSet(uint8_t *byte, uint8_t position) {
|
|
|
|
if(position > 7) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
|
|
|
*byte |= 1 << shiftNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bitutil::bitToggle(uint8_t *byte, uint8_t position) {
|
|
|
|
if(position > 7) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
|
|
|
*byte ^= 1 << shiftNumber;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bitutil::bitClear(uint8_t *byte, uint8_t position) {
|
|
|
|
if(position > 7) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
|
|
|
*byte &= ~(1 << shiftNumber);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bitutil::bitGet(const uint8_t *byte, uint8_t position) {
|
|
|
|
if(position > 7) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
|
|
|
return *byte & (1 << shiftNumber);
|
|
|
|
}
|