+ 3
What is ^ ?
what does ^ sign means in C#. I have tried it with integer and the results were odd. Please help. 0 ^ 2 = 2 , 1 ^ 2 = 3 , 2 ^ 2 = 0, 3 ^ 2 = 1 ?????
4 Antworten
+ 8
it is the XOR operator, it's a bitwise operator which works on the bit level of the variables
XOR returns True if the bits on two corresponding indexes are not the same, and False otherwise:
True XOR True = False
False XOR False = False
True XOR False = True
False XOR True = True
let's examine some of your examples:
i will represent the variables with their bits equivalents using 4 bits and we need to find x each time:
0 ^ 2 = x
0 = 0000
2 = 0010
x = 0010 = 2
1 ^ 2 = x
1 = 0001
2 = 0010
x = 0011 = 3
2 ^ 2 = x
2 = 0010
2 = 0010
x = 0000 = 0
3 ^ 2 = x
3 = 0011
2 = 0010
x = 0001 = 1
hope i clarified it rather than making it worse :p
+ 4
sure thing :D
+ 3
@Burey thanks for helping me in this issue. I was totally confused. You have cleared my concept. I will learn more about bitwise operators. Again thanks for the answer.
+ 1
well explained.