473,732 Members | 2,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ALLCONS TANTS;
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 13428
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.ALLCONS TANTS;
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.c om> 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.ALLCONS TANTS;
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.c om> 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.ALLCONS TANTS;
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
17538
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 18 would be 13 .) I thought this was what the tilde operator (~) did, but when I went to try it I found out that wasn't the case. I discovered by experiment (and verified by looking at the documentation) that the tilde operator takes n to -(n+1)....
8
4592
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 seen in this code: #include<iostream> using namespace std; int main(){
34
16867
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 assumes 32 bit integers. Is there a portable/standard way to do this? Or are ANSI integers always 32 bits? If not, is using sizeof(int) * 8 - 1 as the shift value an acceptable alternative?
2
3466
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 with 2's complement, 1's complement, or sign-magnitude arithmetic. But the followup remark is sometimes also made that the choice of arithmetic isn't completely unconstrained, since the bitwise operators seem to presume a base-2 machine.
3
12493
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 hair....especially ANSI C's bitwise operators..... For reference i come from the (Java/C#/C++) realm and was never forced to use these. Many people dont understand these....I tried to make sense....I know the truth tables...and I can do simple...
3
13148
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 work but doesn't: byteArray &= ~0xe0; // set the first three bits to 0 (11100000 == 0xe0) The error is "Constant value '-225' cannot be converted to a 'byte'".
11
2861
by: subramanian | last post by:
Consider the following code: #include<stdio.h> int main(void) { unsigned char c = 0; unsigned int i = ~c;
1
1802
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 have one question regarding the section "Compute the minimum (min) or maximum (max) of two integers without branching"
1
3140
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 the range +128 to -128 and (2) dispaly an arbitrary user-input integer. main method: *declare int number = 128: got this *include a while loop that loops while number is >=-128: I think i have this *call the display method, which...
0
8946
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9307
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8186
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.