By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,727 Members | 1,263 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,727 IT Pros & Developers. It's quick & easy.

simple not on int or uint

P: n/a
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
Oct 10 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Oct 10, 9:20 am, "Jure Bogataj" <jure.boga...@mikrocop.comwrote:
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

Oct 10 '07 #2

P: n/a
Jure Bogataj wrote:
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-
Oct 10 '07 #3

P: n/a
Hi,

"Jure Bogataj" <ju**********@mikrocop.comwrote in message
news:uy*************@TK2MSFTNGP05.phx.gbl...
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)
Oct 10 '07 #4

P: n/a
Thank you all for your replies! It works!

Best regards,
Jure
"Jure Bogataj" <ju**********@mikrocop.comwrote in message
news:uy*************@TK2MSFTNGP05.phx.gbl...
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

Oct 10 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.