Possible Duplicate:
What are the | and ^ operators used for?
In c# what does the ^ character do?
The ' |= ' symbol is the bitwise OR assignment operator.
In mathematics, the tilde often represents approximation, especially when used in duplicate, and is sometimes called the "equivalency sign." In regular expressions, the tilde is used as an operator in pattern matching, and in C programming, it is used as a bitwise operator representing a unary negation (i.e., "bitwise ...
Summary. An operator is a symbol which operates on a variable or value. There are types of operators like arithmetic, logical, conditional, relational, bitwise, assignment operators etc. Some special types of operators are also present in C like sizeof(), Pointer operator, Reference operator etc.
In C/C++, the # sign marks preprocessor directives. If you're not familiar with the preprocessor, it works as part of the compilation process, handling includes, macros, and more.
This is binary XOR
operator.
Binary ^ operators are predefined for the integral types and bool. For integral types, ^ computes the bitwise exclusive-OR of its operands. For bool operands, ^ computes the logical exclusive-or of its operands; that is, the result is true if and only if exactly one of its operands is true.
The ^ charater, or 'caret' character is a bitwise XOR operator. e.g.
using System;
class Program
{
static void Main()
{
// Demonstrate XOR for two integers.
int a = 5550 ^ 800;
Console.WriteLine(GetIntBinaryString(5550));
Console.WriteLine(GetIntBinaryString(800));
Console.WriteLine(GetIntBinaryString(a));
Console.WriteLine();
// Repeat.
int b = 100 ^ 33;
Console.WriteLine(GetIntBinaryString(100));
Console.WriteLine(GetIntBinaryString(33));
Console.WriteLine(GetIntBinaryString(b));
}
/// <summary>
/// Returns binary representation string.
/// </summary>
static string GetIntBinaryString(int n)
{
char[] b = new char[32];
int pos = 31;
int i = 0;
while (i < 32)
{
if ((n & (1 << i)) != 0)
{
b[pos] = '1';
}
else
{
b[pos] = '0';
}
pos--;
i++;
}
return new string(b);
}
}
^^^ Output of the program ^^^
00000000000000000001010110101110
00000000000000000000001100100000
00000000000000000001011010001110
00000000000000000000000001100100
00000000000000000000000000100001
00000000000000000000000001000101
http://www.dotnetperls.com/xor
Take a look at MSDN ^ Operator (C# Reference)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With