Home Segments Index Top Previous Next

471: Mainline

When you arrange for a particular bit to hold a binary 1, corresponding to an on switch, you are said to set the bit. When you arrange for a particular bit to hold a binary 0, corresponding to an off switch, you are said to reset the bit.

Now you need to know how to set a particular bit without altering any others. First, recall that, viewed as an integer, a byte with a single bit set can be interpreted as an integer that is a power of 2:

*---*---*---*---*---*---*---*---* 
| 0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | <-- Corresponds to 1 
*---*---*---*---*---*---*---*---* 
*---*---*---*---*---*---*---*---* 
| 0 | 0 | 0 | 0 | 0 | 0 | 1 | 0 | <-- Corresponds to 2 
*---*---*---*---*---*---*---*---* 
*---*---*---*---*---*---*---*---* 
| 0 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | <-- Corresponds to 4 
*---*---*---*---*---*---*---*---* 
*---*---*---*---*---*---*---*---* 
| 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | <-- Corresponds to 8 
*---*---*---*---*---*---*---*---*