473,385 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to deconstruct the result of bitwise OR

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
Nov 21 '05 #1
3 2205

"Steve Long" <St**********@NoSpam.com> 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
Nov 21 '05 #2
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" <St**********@NoSpam.com> wrote in message
news:OI**************@TK2MSFTNGP09.phx.gbl... 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

Nov 21 '05 #3
Thanks guys. That helps a lot. I appreciate the input.

Steve

"Steve Long" <St**********@NoSpam.com> wrote in message
news:OI**************@TK2MSFTNGP09.phx.gbl...
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

Nov 21 '05 #4

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

Similar topics

6
by: jas_lx | last post by:
The basic understanding of what bitwise operators (& ^ | >> << ) comes fairly simple, as long as one has a fundamental understanding of bits, bytes and binary. Having done some Win32...
8
by: Paul E Collins | last post by:
Suppose I have a few Keys objects: Keys k1 = Keys.V; // V Keys k2 = Keys.Control | Keys.V; // Ctrl+V Keys k3 = Keys.Shift | Keys.J; // Shift+J I need to determine which of these include the...
9
by: Christopher Weaver | last post by:
I know that the bitwise AND of 8 and 4 will return 0 or false and the bitwise AND of 8 and 9 will return 1 or true but I don't know how to write the synax for it in C#. I have a value that ranges...
5
by: noridotjabi | last post by:
I'm learning to program in C and any tutorial or book that I read likes to briefly touch on birdies operators and then move on without giving any sort of example application of them. Call me what...
12
by: Mick_fae_Glesga | last post by:
OK, the solution to this is probably blindingly obvious to everyone, but... surely it can't be right. I am compiling with borland bcc32 free compiler this piece of code is designed to identify...
3
by: Jay Ruyle | last post by:
I'm trying to figure out a way to list several items in a listbox and let the user select any number of items in the listbox. I have tried to code in the items as bitwise items but all it stores...
5
by: Gigs_ | last post by:
Can someone explain me bitwise expression? few examples for every expression will be nice x << y Left shift x >y Right shift x & y Bitwise AND x | y Bitwise OR x ^ y Bitwise XOR (exclusive...
45
by: Carramba | last post by:
Hi! I now that I can't do straight forward any bitwise operation on float (double etc..). But I wondering what is the easiest/best way to do this? I was thinking if I have float x=1.1111 so I can...
29
by: Carl Banks | last post by:
Anyone with me here? (I know the deadline for P3 PEPs has passed; this is just talk.) Not many people are bit-fiddling these days. One of the main uses of bit fields is flags, but that's not...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
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,...
0
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...
0
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...

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.