473,237 Members | 1,086 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,237 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 13349
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...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

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.