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

  • Thread starter Thread starter Bill Dee
  • Start date Start date
B

Bill Dee

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!
 
Bill said:
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).
 
Bill Dee said:
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
 
* "Bill Dee said:
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 ...'.
 
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!
 
Back
Top