2021-07-13 20:22:54 +02:00
|
|
|
#include "fsfw/globalfunctions/bitutility.h"
|
2021-02-28 16:34:11 +01:00
|
|
|
|
2021-11-10 18:48:02 +01:00
|
|
|
void bitutil::set(uint8_t *byte, uint8_t position) {
|
2022-02-02 10:29:30 +01:00
|
|
|
if (position > 7) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
|
|
|
*byte |= 1 << shiftNumber;
|
2021-02-28 16:34:11 +01:00
|
|
|
}
|
|
|
|
|
2021-11-10 18:48:02 +01:00
|
|
|
void bitutil::toggle(uint8_t *byte, uint8_t position) {
|
2022-02-02 10:29:30 +01:00
|
|
|
if (position > 7) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
|
|
|
*byte ^= 1 << shiftNumber;
|
2021-02-28 16:34:11 +01:00
|
|
|
}
|
|
|
|
|
2021-11-10 18:48:02 +01:00
|
|
|
void bitutil::clear(uint8_t *byte, uint8_t position) {
|
2022-02-02 10:29:30 +01:00
|
|
|
if (position > 7) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8_t shiftNumber = position + (7 - 2 * position);
|
|
|
|
*byte &= ~(1 << shiftNumber);
|
2021-02-28 16:34:11 +01:00
|
|
|
}
|
|
|
|
|
2022-02-02 10:29:30 +01:00
|
|
|
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;
|
2021-02-28 16:34:11 +01:00
|
|
|
}
|