Often controlling hardware involves turning particular bits on or off or checking their status. The bitwise operators provide the means to perform such actions. We’ll go through the methods quickly.

In the following examples, `lottabits`

represents a general value, and `bit`

represents the value corresponding to a particular bit. Bits are numbered from right to left, beginning with bit 0, so the value corresponding to bit position n is 2^{n}. For example, an integer with only bit number 3 set to `1`

has the value 2^{3} or `8`

. In general, each individual bit corresponds to a power of 2, as described for binary numbers in Appendix A. So we’ll use the term *bit* to represent a power of 2; this corresponds to a particular ...

Start Free Trial

No credit card required