473,546 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Working with flags..

Hi. I'm using the | operator to use multiple flags in a variable. For
example:

const int flag1 = 0x00000001;
const int flag2 = 0x00000002;
const int flag3 = 0x00000004;

int Flags = flag2 | flag4 | flag1;

Now I would like to remove flag2 from Flags without having to assign the
other flags (since I'm not sure which are enabled). I believe it's something
like

Flags = Flags (operator) flag2;

but i'm not sure about the operator.

Thanks in advance.
Nov 16 '05 #1
3 2546
Ignacio X. Domínguez wrote:
Hi. I'm using the | operator to use multiple flags in a variable. For
example:

const int flag1 = 0x00000001;
const int flag2 = 0x00000002;
const int flag3 = 0x00000004;

int Flags = flag2 | flag4 | flag1;

Now I would like to remove flag2 from Flags without having to assign
the other flags (since I'm not sure which are enabled). I believe it's
something like
Flags &= ~flag2;
Flags = Flags (operator) flag2;

Flags = Flags & (~flag2);
By the way: Why do you not use an enum !?

[Flags]
public enum PossibleFlags : int
{
flag1 = 0x1,
flag2 = 0x2,
flag3 = 0x4,
}

PossibleFlags Flags;
Flags = PossibleFlags.f lag1 | PossibleFlags.f lag2 | PossibleFlags.f lag3;

Flags &= ~PossibleFlags. flag2;
--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
Nov 16 '05 #2
Thanks. Yes, actually I'm using an enum, but to simplify the post I ommitted
that part. Thank you very much.
"Jochen Kalmbach" <no************ ********@holzma .de> wrote in message
news:Xn******** *************** ***********@207 .46.248.16...
Ignacio X. Domínguez wrote:
Hi. I'm using the | operator to use multiple flags in a variable. For
example:

const int flag1 = 0x00000001;
const int flag2 = 0x00000002;
const int flag3 = 0x00000004;

int Flags = flag2 | flag4 | flag1;

Now I would like to remove flag2 from Flags without having to assign
the other flags (since I'm not sure which are enabled). I believe it's
something like


Flags &= ~flag2;
Flags = Flags (operator) flag2;

Flags = Flags & (~flag2);
By the way: Why do you not use an enum !?

[Flags]
public enum PossibleFlags : int
{
flag1 = 0x1,
flag2 = 0x2,
flag3 = 0x4,
}

PossibleFlags Flags;
Flags = PossibleFlags.f lag1 | PossibleFlags.f lag2 | PossibleFlags.f lag3;

Flags &= ~PossibleFlags. flag2;
--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/

Nov 16 '05 #3
XOR:

Flags ^= flag2;
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
2313
by: Xah Lee | last post by:
Python re module has methods flags and pattern. How to use these exactly? e.g. i tried print patternObj.flags() and the error is some "int object is not callable". newpattern=re.compile(ur'\w+',patternObj.flags())
7
1863
by: loquak | last post by:
Greets. I wonder which way would be the best for holding some state flags in terms of memory use and efficiency. a) struct FLAGS { bool flag1 : 1; bool flag2 : 1;
6
2901
by: Alexis Gatt | last post by:
Hi guys, I was reading the source code of a lib, and I came across this odd way of defining flags #define PHONG_RV (0<<0) #define PHONG_NH (1<<0) Here is how they're used:
13
2046
by: Mark A. Odell | last post by:
I write a lot of drivers and there is inevitably some hardware register or buffer descriptor field called 'flags'. The flags are defined, typically, as bit positions. I was thinking I could get some compile-time type checking when assigning to a flag field but I don't think I can. Here's what I was thinking: typedef unsigned long HwFlag;...
1
4155
by: todorov-fkt | last post by:
Hello everyone, I have a field which is 1 byte long and is used to store different flags (according to specs) - it is the flags bit in the ID3 tag header. So 0xabc00000 represents the byte, where only bits a,b and c have any meaning, the other bits are always 0. I also have the following: enum ID3_Header_Flags { NoFlag = 0x00000000,...
1
10415
by: Dwight.Dexter | last post by:
I have an enum variable. Is there some way to cast an int or BitArray and get my enum value? I have to communicate with an old C-style sever so I get an array of bits("0","1"). But I'm using an enum variable to store the data. public enum LaneCapabilities { MLT = 0, ACM = 1,
1
4275
by: RicercatoreSbadato | last post by:
I have notice that my images have the value Image.Flags = 2 (HasAlpha). How Can I set the Flags to 1? I would like to eliminate the alpha channel... -- RicercatoreSbadato
4
5044
by: Joel Moore | last post by:
Say I have an enum similar to this: <Flags()> Enum TestFlags As Short One = 0 Two = 1 Three = 2 Four = 4 End Enum I figured I could declare variable of type TestFlags to be used in the
1
3832
by: Alexander Korsunsky | last post by:
Hi! Is it possible to extract the mode flags of a stream (FILE* stream or fstream - object), without looking at how the stream was opened? What I mean by mode flags is wether the stream is opened in read only mode, write only, binary and so on. I did not find any functions in C, but I found something similar in C++, the flags() member...
0
7507
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7947
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6030
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5361
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5080
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1922
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.