Home Segments Index Top Previous Next

482: Mainline

The shift operators, << and >> move the bits in the left-side operand as far as specified by the right-side operand. If m is a mask that allows passage of bits 0 and 3, you can shift the on bits two places to the left, creating a mask that allows passage of bits 2 and 5:

m 
*-*-*-*-*-*-*-*-* 
|0|0|0|0|1|0|0|1| ----* 
*-*-*-*-*-*-*-*-*     | 
         |     |      | 
     *---* *---*      v  Action of m << 2 
     |     |          | 
     v     v          | 
*-*-*-*-*-*-*-*-*     | 
|0|0|1|0|0|1|0|0| <---* 
*-*-*-*-*-*-*-*-* 

Similarly, you can shift the on bits two places to the right, losing the 0 bit, creating a mask that allows passage of bit 1 only:

m 
*-*-*-*-*-*-*-*-* 
|0|0|0|0|1|0|0|1| ----* 
*-*-*-*-*-*-*-*-*     | 
         |            | 
         |            | 
         *---*        v  Action of m >> 2 
             |        | 
             v        | 
*-*-*-*-*-*-*-*-*     | 
|0|0|0|0|0|0|1|0| <---* 
*-*-*-*-*-*-*-*-*