c# - Use of Bitwise AND (&) in this scenario -


i've seen explanations of & (and plenty of explanations of |) around (here etc), none clarify use of & in following scenario:

else if ((e.allowedeffect & dragdropeffects.move) == dragdropeffects.move)  {...} 

taken msdn

can explain this, specific usage?

thanks.

e.allowedeffect possibly combination of bitwise flags. & operator performs bit bit "and" logical operation each bit. result if bit under test one, result single flag. test writter in way same result:

else if ((e.allowedeffect & dragdropeffects.move) != 0 )  {...} 

lets explain better example, flag value these:

none = 0,      copy = 1,      move = 2,      link = 4, 

so in binary:

none = 00000000,

copy = 00000001,  move = 00000010,  link = 00000100, 

so consider case in under test have combination of copy , move, ie value be:

00000011 

by bitwise , move have:

00000011  -->copy | move 00000010  -->move ======== & 00000010 === move 

Comments