larockd
asked on
Bitwise And Operation
I am confused on Bit Comparisons. When doing a comparison of two bit values -> example
if ((nFlags & MK_LBUTTON)==MK_LBUTTON)
cout .....
Assuming that MK_LBUTTON = 00000001 and nFlags was Unknown
If nFlags was equal to 01010101 , the if statement would be true? or does nFlags have to 00000001? Basically what I am asking is that when doing the comparision is it checking for only the one in the last bit or is it comparing the entire byte? Can someone explain how this all works and what it might be useful for?
Thanks
DArrell
if ((nFlags & MK_LBUTTON)==MK_LBUTTON)
cout .....
Assuming that MK_LBUTTON = 00000001 and nFlags was Unknown
If nFlags was equal to 01010101 , the if statement would be true? or does nFlags have to 00000001? Basically what I am asking is that when doing the comparision is it checking for only the one in the last bit or is it comparing the entire byte? Can someone explain how this all works and what it might be useful for?
Thanks
DArrell
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if ((nFlags & MK_LBUTTON)==MK_LBUTTON)
As long as the last bit of nFlags is 1, it will be true. It is the same as
if ((nFlags & MK_LBUTTON)!=0) but the latter is more common.