simple not on int or uint

  • Thread starter Thread starter Jure Bogataj
  • Start date Start date
J

Jure Bogataj

Hello!

Why I cannot apply this operator to UINT or INT type in c# (VS 2005)?

uint MyConst;
uint SomeValue;
....
MyConst = MyConst & (!SomeValue)

Trying to erase certain bit inside MyConst. I come from Delphi world and the
translation would be
MyConst = MyConst and (not SomeValue)
where (not SomeValues) turns bits arround (0==>1, 1==>0)

How can the same thing be accomplished in c#?

best regards,
Jure
 
Hello!

Why I cannot apply this operator to UINT or INT type in c# (VS 2005)?

uint MyConst;
uint SomeValue;
...
MyConst = MyConst & (!SomeValue)

Trying to erase certain bit inside MyConst. I come from Delphi world and the
translation would be
MyConst = MyConst and (not SomeValue)
where (not SomeValues) turns bits arround (0==>1, 1==>0)

How can the same thing be accomplished in c#?

best regards,
Jure

Hi Jure,
I think you want the bitwise operator ~ . Try something like this:
uint MyConst = 255;
uint SomeValue = 2;
MyConst = MyConst & ~SomeValue;
John
 
Hi,

Jure Bogataj said:
Hello!

Why I cannot apply this operator to UINT or INT type in c# (VS 2005)?

uint MyConst;
uint SomeValue;
...
MyConst = MyConst & (!SomeValue)

I think that the operator you are looking for is ~ :

MyConst = MyConst & (~SomeValue)
 
Jure said:
Hello!

Why I cannot apply this operator to UINT or INT type in c# (VS 2005)?

uint MyConst;
uint SomeValue;
...
MyConst = MyConst & (!SomeValue)

Trying to erase certain bit inside MyConst. I come from Delphi world and the
translation would be
MyConst = MyConst and (not SomeValue)
where (not SomeValues) turns bits arround (0==>1, 1==>0)

How can the same thing be accomplished in c#?

I think you want "~", not "!", as per:

uint seven = 7;
uint four = 4;
uint threeihope = seven & ~four;

Console.WriteLine("result = " + threeihope);
Console.ReadLine();

HTH,
-rick-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top