Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


Clear a bit.

Posted on 1998-10-25
Medium Priority
Last Modified: 2010-04-15

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!

Question by:termination
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

thresher_shark earned 600 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!

Author Comment

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!

Expert Comment

ID: 1253816
Glad I could help! :-)

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses

597 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