473,396 Members | 1,996 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,396 software developers and data experts.

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 13374
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Elaine Jackson | last post by:
Is there a function that takes a number with binary numeral a1...an to the number with binary numeral b1...bn, where each bi is 1 if ai is 0, and vice versa? (For example, the function's value at...
8
by: J. Campbell | last post by:
When the bitwise NOT operator, is placed in front of an integer variable type (bool, char, short, int, long), the return value is a signed int, regardless of the variable type. An example can be...
34
by: Christopher Benson-Manica | last post by:
I'm trying to compute the absolute value of an integer using only bitwise operators... int x; sscanf( "%d", &x ); printf( "%d\n", (x^((~((x>>31)&1))+1)) + ((x>>31)&1) ); That works, but it...
2
by: Steve Summit | last post by:
-----BEGIN PGP SIGNED MESSAGE----- It's often explained that the reason for some of the imprecision in C's definition is so that C can be implemented on different kinds of machines -- say, those...
3
by: shdwsclan | last post by:
I am native to various languages but bitwise operators just kill me. I see how much I take object oriented languages for granted. I like all the other c derivitives but ANSI C is making me loose my...
3
by: Marc | last post by:
I'm trying to set the first three bits to zero on a byte. For some reason, the compiler is casting the number peculiarly when I use the bitwise complement operator. Here's what I think should...
11
by: subramanian | last post by:
Consider the following code: #include<stdio.h> int main(void) { unsigned char c = 0; unsigned int i = ~c;
1
by: somenath | last post by:
Hello All, I was trying to learn bitwise operator in C .In that process I cam across one resource as mentioned bellow http://graphics.stanford.edu/~seander/bithacks.html#OperationCounting I...
1
by: DDAVE2010 | last post by:
I currently have the display method down, but I am not sure where to go with the main method... Write a program that uses bitwise operations to: (1) generate and display all power-of-two number in...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.