I'd like to set a specific bit to 0 but without using a bitmask because I'm using enums and if the enum values change, enum fields get moved around then the bitmask would no longer be valid.
I can toggle a bit on, using a temporary variable then OR it with the already existing bitfield
#include <assert.h>
enum EState{
k_EStateNone,// bit 1 - 1
k_EStateFoo,// bit 2 - 10
k_EStateBar// bit 3 - 100
};
uint64_t togglebiton(uint64_t state,EState ebit){
uint64_t temp = 1<<ebit;
state|=temp;
return state;
}
int main(){
uint64_t state = 0;
state = togglebiton(state, k_EStateBar);
state = togglebiton(state, k_EStateFoo);
//foo bar = 110 == 6
assert(state == 6);
return 0;
}
But I'm unsure how to go about flipping the bit off, because I can't AND the whole thing with 0..