Worth noting is that take caution when applying multiple "flag operations"
in the same line of code.  The below example of "flags | C & ~B" really
translates to "flags | (C & ~B)"  which will give the wrong result.  Just
use the good old parenthese to be safe.

Chad

On Tue, 29 Jun 2004 07:41:40 +0300, Stoyan Damov <[EMAIL PROTECTED]> wrote:

>No, you couldn't. If you have set the flags *in runtime* to A | B and you
>want to "add" (set also) C, but "remove" (clear) B, you should either know
>which flags were set previously or just type "flags | C & ~B".
>
>Cheers,
>Stoyan
>
>-----Original Message-----
>From: Unmoderated discussion of advanced .NET topics.
>[mailto:[EMAIL PROTECTED] On Behalf Of William
>Bartholomew
>Sent: Tuesday, June 29, 2004 02:25
>To: [EMAIL PROTECTED]
>Subject: Re: [ADVANCED-DOTNET] bits of an integer
>
>Could you not use an enumeration with the Flags attribute and avoid all
>of the casting to int?
>
>Regards,
>
>William D. Bartholomew
>http://blog.bartholomew.id.au/
>
>
>JJ hughes wrote:
>> i ended up setting the bit back like this
>> what I needed to do was set 4 bits in a integer (1,2,4,8) these bits
>> represented boolean values
>> So I set them via check boxes on a web form and change the value in the
>bit
>> if it evaluates to false
>>
>> if(value){this.modality |= (int)Modalities.OnLine;}
>> else{this.modality &= ~((int)Modalities.OnLine);}
>>
>> Thank you,
>>
>> Jeff Hughes
>> Spider Web Development LLC
>> 480-215-9493
>> [EMAIL PROTECTED]
>> http://spiderwebdev.com
>>
>>>this.modality = this.modality | 1; will set the least significant bit
>>>
>>>-----Original Message-----
>>>From: Unmoderated discussion of advanced .NET topics.
>>>[mailto:[EMAIL PROTECTED] On Behalf Of jeff Hughes
>>>Sent: Monday, June 28, 2004 2:03 PM
>>>To: [EMAIL PROTECTED]
>>>Subject: [ADVANCED-DOTNET] bits of an integer
>>>
>>>I am trying to set the bits of an integer value. I am able to get the
bit
>>>set like this
>>>
>>>if((someIntValue & 1) == 1)
>>>{
>>>  return true;
>>>}
>>>
>>>so if the the first bit == 1 then I know that bit is set
>>>
>>>if I want to set the bit to one I get and execption
>>>
>>>trying this way I get "The left-hand side of an assignment must be a
>>>vaiable, propery or indexer"
>>>
>>>(this.modality & 1) = 1;
>>>
>>>how do I set the bit of the integer?
>>>
>>>JJ
>>>
>>>===================================
>>>This list is hosted by DevelopMentorR  http://www.develop.com Some .NET
>>>courses you may be interested in:
>>>
>>>NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
>>>http://www.develop.com/courses/gaspdotnetls
>>>
>>>View archives and manage your subscription(s) at
>>
>> http://discuss.develop.com
>>
>>>===================================
>>>This list is hosted by DevelopMentorR  http://www.develop.com
>>>Some .NET courses you may be interested in:
>>>
>>>NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
>>>http://www.develop.com/courses/gaspdotnetls
>>>
>>>View archives and manage your subscription(s) at
>>
>> http://discuss.develop.com
>>
>>
>> ===================================
>> This list is hosted by DevelopMentorR  http://www.develop.com
>> Some .NET courses you may be interested in:
>>
>> NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
>> http://www.develop.com/courses/gaspdotnetls
>>
>> View archives and manage your subscription(s) at
>http://discuss.develop.com
>>
>>
>>
>> ---
>> avast! Antivirus: Inbound message clean.
>> Virus Database (VPS): 0426-1, 25/06/2004
>> Tested on: 29/06/2004 9:02:02 AM
>> avast! - copyright (c) 2000-2004 ALWIL Software.
>> http://www.avast.com
>>
>>
>>
>>
>
>
>---
>avast! Antivirus: Outbound message clean.
>Virus Database (VPS): 0426-1, 25/06/2004
>Tested on: 29/06/2004 9:24:56 AM
>avast! - copyright (c) 2000-2004 ALWIL Software.
>http://www.avast.com
>
>===================================
>This list is hosted by DevelopMentorR  http://www.develop.com
>Some .NET courses you may be interested in:
>
>NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
>http://www.develop.com/courses/gaspdotnetls
>
>View archives and manage your subscription(s) at
http://discuss.develop.com
>
>===================================
>This list is hosted by DevelopMentorŪ  http://www.develop.com
>Some .NET courses you may be interested in:
>
>NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
>http://www.develop.com/courses/gaspdotnetls
>
>View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentorŪ  http://www.develop.com
Some .NET courses you may be interested in:

NEW! Guerrilla ASP.NET, 17 May 2004, in Los Angeles
http://www.develop.com/courses/gaspdotnetls

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to