468,463 Members | 1,906 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,463 developers. It's quick & easy.

Bitwise complement operator in VB.NET like in C#?

I need help converting a tiny piece of code which uses the bitwise
complement operator from C# to VB.NET.

In C# I currently have this:

long useThis = Myclass.ALLCONSTANTS;
long doNotUse = Mycalls.ABC | Myclass.XYX;
long useThis &= ~doNotUse; bitwise removal of flags not to use

How do I convert this to VB.NET? I know to use "OR" instead of " | "
characters in the "long doNotUse =" line. But I am stuck on how to convert
the last line shown from C# to VB.NET. It does not look like there is an
equivilent ~ operator in VB.NET?

Assuming there is no short-hand way to do this in VB.NET, what type of code
(looping of some sort?) with supported bitwise operations can I use to
effectively perform the same results? A tiny code snippet/example
demonstrating how I can handle this would be easiest to follow and most
appreciated.

Thanks!

Nov 20 '05 #1
5 12514
Bill Dee wrote:
I need help converting a tiny piece of code which uses the bitwise
complement operator from C# to VB.NET.

In C# I currently have this:

long useThis = Myclass.ALLCONSTANTS;
long doNotUse = Mycalls.ABC | Myclass.XYX;
long useThis &= ~doNotUse; bitwise removal of flags not to use

How do I convert this to VB.NET? I know to use "OR" instead of " | "
characters in the "long doNotUse =" line. But I am stuck on how to
convert the last line shown from C# to VB.NET. It does not look like
there is an equivilent ~ operator in VB.NET?


Yes there is, it's "Not".

The equivalent of your third line is
useThis = useThis And Not doNotUse

I've assumed you're not actually declaring useThis on that line like you do
in your example above, because if you do the statement makes no sense
(useThis is zero after declaration, and will remain zero after the
statement).

--
Sven Groot

http://unforgiven.bloghorn.com

Nov 20 '05 #2
"Bill Dee" <sp**@spamabc.com> schrieb
I need help converting a tiny piece of code which uses the bitwise
complement operator from C# to VB.NET.

In C# I currently have this:

long useThis = Myclass.ALLCONSTANTS;
long doNotUse = Mycalls.ABC | Myclass.XYX;
long useThis &= ~doNotUse; bitwise removal of flags not to use

How do I convert this to VB.NET? I know to use "OR" instead of " |
" characters in the "long doNotUse =" line. But I am stuck on how to
convert the last line shown from C# to VB.NET. It does not look like
there is an equivilent ~ operator in VB.NET?

Assuming there is no short-hand way to do this in VB.NET, what type
of code (looping of some sort?) with supported bitwise operations can
I use to effectively perform the same results? A tiny code
snippet/example demonstrating how I can handle this would be easiest
to follow and most appreciated.

Thanks!

Use the Not operator to flip all bits, so I think

usethis = usethis and (not donotuse)

is the equivalent.
--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #3
Hi Bill,

Two very nice pages for this

Code C# and VB
http://www.harding.edu/USER/fmccown/...omparison.html

Language compare
http://msdn.microsoft.com/library/en...quivalents.asp

I hope this helps?

Cor
Nov 20 '05 #4
* "Bill Dee" <sp**@spamabc.com> scripsit:
I need help converting a tiny piece of code which uses the bitwise
complement operator from C# to VB.NET.

In C# I currently have this:

long useThis = Myclass.ALLCONSTANTS;
long doNotUse = Mycalls.ABC | Myclass.XYX;
long useThis &= ~doNotUse; bitwise removal of flags not to use

How do I convert this to VB.NET? I know to use "OR" instead of " | "


VB.NET's 'Not' operator is overloaded, just use '... = ... And Not ...'.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 20 '05 #5
> useThis = useThis And Not doNotUse

Thanks fot all - this worked great.
I've assumed you're not actually declaring useThis on that line like you

do

Right, typo on my part. Thanks again, much appreciated!
Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Elaine Jackson | last post: by
8 posts views Thread by J. Campbell | last post: by
34 posts views Thread by Christopher Benson-Manica | last post: by
2 posts views Thread by Steve Summit | last post: by
11 posts views Thread by subramanian | last post: by
1 post views Thread by somenath | last post: by
1 post views Thread by DDAVE2010 | last post: by
reply views Thread by kmladenovski | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.