Control hardware often involves opening/closing specific bits or viewing their status. The bitwise operator (<<,>>,~,&,|,^) provides this capability. In the following example, Lottabits represents a value, bit represents the value of a special location. Bits are numbered from right to left, starting with 0, so that the nth bit has a value of 2 n (usually only one is 1, which is for brevity). For example, only an integer with a 3rd bit of 1 is the value of 2 for the 3-time square. ("C + + Primer Plus" Appendix E)
1. Open the bit
Opens a bit that will open the bit in the lottabits corresponding to the bit representation
Lottabits=lottabits|bit;
2. Toggle Bit
Toggle bit, will swap lottabits with bit
Lottabits=lottabits^bit;
3. Close the bit
Turns off the bit that corresponds to the bit representation in the Lottabits
lottabits=lottabits&~bit;
4. Test the value of the bit
The value of the test bit
if (lottabits&bit);
Several commonly used bitwise operator techniques