Solved

Clear a bit.

Posted on 1998-10-25
3
199 Views
Last Modified: 2010-04-15
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
0
Comment
Question by:termination
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
thresher_shark earned 150 total points
ID: 1253814
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
 

Author Comment

by:termination
ID: 1253815
That seems to have solved my problem.  I will give you the points... let's see here... ah yes.  Here we go.  Thanks!
0
 
LVL 6

Expert Comment

by:thresher_shark
ID: 1253816
Glad I could help! :-)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now