• C

Clear a bit.

Hi.

I have a couple bytes that I am using for flags.  How do I clear a bit (set it to 0)?  I know how to set bits and flip bits, but I can't clear bits!

Thanks
terminationAsked:
Who is Participating?
 
thresher_sharkConnect With a Mentor Commented:
If you want to clear a bit, do this:

int a = 128;    // bit 8 is set.
int mask = 128; // You want to clear bit 8.
mask = ~mask;   // FLIP ALL bits of the mask.
a = a & mask;   // Clears bit 8

This principle can be applied with any bit.  If you have any further questions, please feel free to ask.  Thanks!
0
 
terminationAuthor Commented:
That seems to have solved my problem.  I will give you the points... let's see here... ah yes.  Here we go.  Thanks!
0
 
thresher_sharkCommented:
Glad I could help! :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.