Home Segments Index Top Previous Next

481: Mainline

There are four other, occasionally useful, bitwise operators. The bitwise-complement operator, ~, converts 1s to 0s, and vice versa. Thus, if a certain mask, m, allows passage of bits 0 and 3, then ~m allows passage of all bits except bits 0 and 3:

m 
*-*-*-*-*-*-*-*-* 
|0|0|0|0|1|0|0|1| ----* 
*-*-*-*-*-*-*-*-*     | 
                      v  Action of bitwise-complement operator 
*-*-*-*-*-*-*-*-*     | 
|1|1|1|1|0|1|1|0| <---* 
*-*-*-*-*-*-*-*-*