A mask is a bit pattern. Suppose you have this pattern of bits in an unsigned char:
11001010
and you want to see if bit 3 is set (that's the 4th bit from the right). So you use a mask:
00001000
and AND the mask with the bit pattern:
11001010
00001000
------------
00001000
If the result of the AND matches the mask, then the 4th bit is set.
And remember: There is no money in bit-fiddling :)
Sayed in simple English:
Mask used with bit operator & is used to pull out from memory word bits that u wish to use.
Mask used with bit operator |(OR) is used to set bit or bits in state 1,independent from they previous state.Thats why we use with it mask that in does positions have value of 1 and in all other value of 0
e.g
0100101010111001
|
0000000000110001
---------------------------
0100101010111001
Mask used with operator ^ has nearly the same tautology as a | operator.Only differance is that when using ^ 1 and 1 will result in 0 and it's well suited to test equality of two different memory words
e.g
0000100111000011
^
0101010010110111
---------------------------
0101111000010100
And last bit operator resembles negation (~)
Savage