If the purpose of the & operation is to check whether bit 1 is set, then the potential βoppositeβ operation is to βset bit 1β.
i.e:.
val = val | 2;
This overwrites the value currently in bit 2 and does not apply to any other bit.
If 8 bits in a byte are considered completely independent bits, then you can change any of them by touching any other.
In this case, it does not matter that some initial information was lost. In fact, we donβt care about what value the other bits had, and most often when using bit masks, the initial value of the bits in question is zero.
Alnitak
source share