I\'ve searched for this, but my results were unsatisfactory, probably because of how hard it is to word. I have one object, state
, which is a byte
that
If you just invert the bits of the parts, you can just AND it with the state
void disableParts(byte parts) {
byte invertOfParts = 0b11111111 - parts;
state &= invertOfParts
}
What you need to do is invert the bits (bit-wise NOT) in partsToDisable
so you end up with a mask where the 1's are the bits to be left alone and the 0's are the bits to be turned off. Then AND this mask with the state value.
public void disableParts( byte partsToDisable)
{
state = state & (~partsToDisable);
}