Remove bits from a DWORD...

This topic is 4737 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I have a flag variable which sets various bits in a DWORD to indicate certain states. I have a method called RemoveFlags() which looks a bit like this:
void ScreenEntityBase::RemoveFlags(DWORD removeFlags)
{
Flags = Flags ^ removeFlags;
}


Which doesn't seem to work. 1. Am I just being stupid? 2. Does anybody know why this doesn't have the desired effect of removing the given bits? Thanks, Mark

Share on other sites
That will flip the flags to remove do:
Flags = Flags & ~removeFlags;

Share on other sites
Not really. Where does flags go afterwards? Is it a member variable? How is this called and with what values? You did not do any operator overloading?

Also not that this will, as a side effect, turn on any bits that should be removed but are not turned on in the flag. Check the XOR table:
F R -----0 0 00 1 1 <-- Flag bit is off; Remove bit is on; Result is on1 0 11 1 0

Greetz

Illco

Share on other sites
Thank you very much.

Mark

• 10
• 17
• 9
• 14
• 41