PC Review


Reply
Thread Tools Rate Thread

How to deconstruct the result of bitwise OR

 
 
Steve Long
Guest
Posts: n/a
 
      25th Oct 2004
this is probably trivial, but, I just am not sure how to do it.

Say I have an argument for a routine that is an enumeration such as
moNone 0 'None
moLong 3 'Long
moDouble 5 'Double
moDate 7 'Date
moString 8 'String

This enum is defined in some other assymbly btw.

So, if I pass in say:
moLong Or moDouble

VB will bitwise Or these two enum members. How do I tell that it is those
two enumeration members? I can't just see if it equals 8 cause that is
another enum member.

I hope I have explained this clearly enough.

Thanks
Steve


 
Reply With Quote
 
 
 
 
Jay B. Harlow [MVP - Outlook]
Guest
Posts: n/a
 
      25th Oct 2004
Steve,
Unfortunately you cannot, as you have overlapping values.

If you are going to Or two Enum values together you need to ensure that each
value has a distinct value.

Such as:

<Flags()> _
Public Enum Mo
> moNone 0
> moLong 1 << 0 ' 1
> moDouble 1 << 1 ' 2
> moDate 1 << 2 ' 4
> moString 1<< 3 ' 8

End Enum

Then you can use Or as you have been to combine then, and use And to check
for a specific value.

Dim x As mo = moLong Or moDouble

If (x And moLong) <> 0 Then
' We have a Long
End If

If (x And moDouble) <> 0 Then
' We have a Double
End If

Const LongDouble As Mo = moLong Or moDouble
If (x And LongDouble) = LongDouble Then
' We have a Long
End If

Note: << & >> requires VB.NET 2003, the Flags attribute on Enum Mo allows
Enum.ToString to display the combined values.

Hope this helps
Jay




"Steve Long" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> this is probably trivial, but, I just am not sure how to do it.
>
> Say I have an argument for a routine that is an enumeration such as
> moNone 0 'None
> moLong 3 'Long
> moDouble 5 'Double
> moDate 7 'Date
> moString 8 'String
>
> This enum is defined in some other assymbly btw.
>
> So, if I pass in say:
> moLong Or moDouble
>
> VB will bitwise Or these two enum members. How do I tell that it is those
> two enumeration members? I can't just see if it equals 8 cause that is
> another enum member.
>
> I hope I have explained this clearly enough.
>
> Thanks
> Steve
>
>



 
Reply With Quote
 
Larry Serflaten
Guest
Posts: n/a
 
      25th Oct 2004

"Steve Long" <(E-Mail Removed)> wrote

> this is probably trivial, but, I just am not sure how to do it.
>
> Say I have an argument for a routine that is an enumeration such as
> moNone 0 'None
> moLong 3 'Long
> moDouble 5 'Double
> moDate 7 'Date
> moString 8 'String
>
> This enum is defined in some other assymbly btw.
>
> So, if I pass in say:
> moLong Or moDouble
>
> VB will bitwise Or these two enum members. How do I tell that it is those
> two enumeration members? I can't just see if it equals 8 cause that is
> another enum member.
>
> I hope I have explained this clearly enough.



The enum is not set up for use as bit flags. To be used as flags, each
item has to have a value that is equal to some power of 2.

1, 2, 4, 8, 16, ...

The way it is, you won't always be able to determine which items were
included....

LFS
 
Reply With Quote
 
Steve Long
Guest
Posts: n/a
 
      25th Oct 2004
Thanks guys. That helps a lot. I appreciate the input.

Steve

"Steve Long" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> this is probably trivial, but, I just am not sure how to do it.
>
> Say I have an argument for a routine that is an enumeration such as
> moNone 0 'None
> moLong 3 'Long
> moDouble 5 'Double
> moDate 7 'Date
> moString 8 'String
>
> This enum is defined in some other assymbly btw.
>
> So, if I pass in say:
> moLong Or moDouble
>
> VB will bitwise Or these two enum members. How do I tell that it is those
> two enumeration members? I can't just see if it equals 8 cause that is
> another enum member.
>
> I hope I have explained this clearly enough.
>
> Thanks
> Steve
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
bitwise xor is giving the wrong result Tony Johansson Microsoft C# .NET 1 7th Feb 2010 12:39 PM
How do I deconstruct or decompose PP in order to make them PDF? MAWhsing4 Microsoft Powerpoint 1 16th Jul 2008 07:04 PM
Re: Can I deconstruct a pps so I have individual slides/pics? Petr Microsoft Powerpoint 0 10th Jan 2007 09:42 PM
"Deconstruct" a large financial report table =?Utf-8?B?Sm9obiBE?= Microsoft Access Database Table Design 6 30th Sep 2006 07:15 PM
Bitwise Or and bitwise shifting..... James Dean Microsoft C# .NET 5 22nd Jun 2004 11:29 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:39 PM.