Archived

This topic is now archived and is closed to further replies.

ITH3

Clearing bits

Recommended Posts

Lets say I have something like this:
      
#define SOLID_TOP    0x00000001 
#define SOLID_BOTTOM 0x00000002 
#define SOLID_LEFT   0x00000004 
#define SOLID_RIGHT  0x00000008

int properties = SOLID_TOP | SOLID_BOTTOM;
      
I want to be able to clear SOLID_TOP from properties and still have SOLID_BOTTOM left in it. How do I do this? Thanks for any help. [edited by - ITH3 on March 16, 2003 6:27:33 PM] [edited by - ITH3 on March 16, 2003 6:28:14 PM]

Share this post


Link to post
Share on other sites
myFlag &= ~FLAG_I_DONT_WANT;

EDIT: Thought I should give some reasons. If FLAG_I_DONT_WANT has a bit set, when you inverse it, everything BUT that bit is now set. When you AND it with myFlag, everything is one, except the bit you don't want, which is 0. That will eliminate your bit from the flag.

[edited by - Zipster on March 16, 2003 6:41:56 PM]

Share this post


Link to post
Share on other sites