Alessandro Zifiglio

Bitwise operators in c# OR(|), XOR(^), AND(&), NOT(~)

All posts have moved to Typps

See you there.

Alessandro

Comments

Seshasai said:

Its excellent. Great job.

# February 4, 2008 10:26 AM

Vesko Kolev said:

I think that it is very good article, too! In the good old days the bitwise operators were part of our everyday life. Now they are used only from the good devs which still think for performance.

P.S. Why not adding some words about << and >> just to cover the whole topic?

Thanks again!

# February 13, 2008 3:39 PM

Brad said:

it is not helpful as I am finding the operator for XNOR operation.

I encrypt the password using XOR operator, now i want to decrypt it. What is the process to achieve this?

# April 28, 2008 5:04 AM

Brad2 said:

Brad, if you XOR something, just XOR it again to get back your original value.

# May 15, 2008 4:03 PM

chethan said:

i want the logic as how to write bitwise xor like

for 101 we get 0 by doing bitwise xor

for 100 we get 1 by doing bitwise xor

# October 7, 2008 6:32 AM

ARUNIMA BHATTACHARYA said:

A GOOD STUFF INDEED.I want to add: If one XORs anything twice he will get the actual number again.That is how one can use it to encrypt and decrypt.

# January 2, 2009 7:51 AM

Arunima Bhattacharya said:

If we want to get 0 for 101 and 1 for 100,it can be assumed that only the LSB is used for XOR operation,now if we XOR the number with 1,i.e.001 then we get the desired output.

# January 2, 2009 7:57 AM

fako said:

this article really helps

# March 2, 2009 10:40 PM

Vojtěch Vít said:

My Thanks to the author. This article is short but very, very clear:-)

# March 15, 2009 3:45 PM

laila said:

greet job:)

but these are built in functions

# March 25, 2009 8:03 AM

F2F said:

i don't understand this article.

for example:

var a = 1;

var b = 2;

if  (a == b ) {

 //do sothing.

}

if i use bitwise operators, i will write:

if (a & b == a) {

 //do sothing

}

is it true ? how about other operators ?

Please help me.

# May 6, 2009 11:09 PM

Alex van Beek said:

Cool use of the ~ operator is the binary search method in the List class. It returns a negative integer when it can't find the specified item. This negative integer becomes the correct insertion point to keep the list sorted, when you apply the ~ operator.

# June 15, 2009 6:34 AM

Kyi Thar said:

Pls help me..

I have to compute for binary Not AND(NAND), NOR and XNOR(Exclusive NOR)in C#. operator ~ and ! are not support for NAND, NOR and XNOR. so pls tell me how to ..

NAND (Not AND)

0 NAN 0 = 1

0 NAN 1 = 1

1 NAN 0 = 1

1 NAN 1 = 0

NOR (Not OR)

0 NOR 0 = 1

0 NOR 1 = 0

1 NOR 0 = 0

1 NOR 1 = 0

XNOR (Exclusive NOR)

0 XOR 0 = 1

0 XOR 1 = 0

1 XOR 0 = 0

1 XOR 1 = 1

# October 16, 2009 7:55 PM

Chris said:

Thanks, very well written and easy to understand post.

# November 19, 2009 2:10 PM

Ganesh said:

Waw gr8 examples,

It's really helpfull for me.

Thankx

# July 14, 2010 1:42 AM

Jaroslaw Dobrzanski said:

Exactly what I was looking for. Thanks!

# September 8, 2010 5:44 AM

arshpreet said:

thanks..........

u hav done a great job....

i was trying to get it form months.........

thanks a lot>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

# September 17, 2010 8:16 AM

Brice said:

Very impressive. Short, but to the point.  I skipped class yesterday an apparently they spent the whole hour going over c# bitwise operators. Took ten min of reading this article to catch up lol.

# October 13, 2010 5:11 PM

Deepak said:

Thanks for writing such an understanding article on Bitwize

# December 2, 2010 6:46 AM

Jake said:

really helpful, thx. some tricks with ~, good explained. As <keep complex...> asked: what's one's complement?

# March 3, 2011 2:21 PM