^=有什么用,它的反义词是什么c#
What is the use of ^= and what is the opposite of it c#
大家好,我想知道这个符号“^”在 C# 中的用途是什么
对于这个简单的代码
public static Byte[] Xor = new Byte[] {0x77, 0xE8, 0x5E, 0xEC, 0xB7};
public static Byte[] data = new Byte[5];
static byte[] convertsomething(){
Byte xors = 0;
for (int i = 0; i < 100; i++)
{
data[i] ^= Xor[xors];
xors++;
}
return data;
}
对于 c# 代码,我们有变量数据,如何将其转换回主代码
值或此操作的相反数 data[i] ^= Xor[xors];
它是一个二元运算符,二元^运算符是为整数类型和bool预定义的
x ^= y
被评估为 x = x ^ y
基本上是 ^ 运算符所允许的
// When one operand is true and the other is false, exclusive-OR
// returns True.
Console.WriteLine(true ^ false);
// When both operands are false, exclusive-OR returns False.
Console.WriteLine(false ^ false);
// When both operands are true, exclusive-OR returns False.
Console.WriteLine(true ^ true);
有关运算符的更多信息@https://msdn.microsoft.com/en-us/library/0zbsw2z6.aspx & https://msdn.microsoft.com/en-us/library/zkacc7k1.aspx
C#中的^ operator is a boolean logical operator, it's purpose is to perfom the Exclusive or (XOR)操作。
对于 bool 操作数,只有当两个操作数之一为真时,此操作的结果才会 return 真,这意味着:
true ^ true // Will return false
false ^ false // Will return false
true ^ false // Will return true
对于整数操作数,它执行按位异或,示例(括号中显示二进制表示):
1 (1) ^ 1 (1) // Will return 0 (0)
0 (0) ^ 0 (0) // Will return 0 (0)
1 (1) ^ 0 (0) // Will return 1 (1)
2 (10) ^ 1 (1) // Will return 3 (11)
15 (1111) ^ 5 (101) // Will return 10 (1010)
^= operator 将对左右操作数执行相同的操作,这意味着 x ^= y 与 x = x ^ y 相同。
异或的道理table可以帮助理解:
A B Result
0 0 0
0 1 1
1 0 1
1 1 0
大家好,我想知道这个符号“^”在 C# 中的用途是什么
对于这个简单的代码
public static Byte[] Xor = new Byte[] {0x77, 0xE8, 0x5E, 0xEC, 0xB7};
public static Byte[] data = new Byte[5];
static byte[] convertsomething(){
Byte xors = 0;
for (int i = 0; i < 100; i++)
{
data[i] ^= Xor[xors];
xors++;
}
return data;
}
对于 c# 代码,我们有变量数据,如何将其转换回主代码 值或此操作的相反数 data[i] ^= Xor[xors];
它是一个二元运算符,二元^运算符是为整数类型和bool预定义的
x ^= y
被评估为 x = x ^ y
基本上是 ^ 运算符所允许的
// When one operand is true and the other is false, exclusive-OR
// returns True.
Console.WriteLine(true ^ false);
// When both operands are false, exclusive-OR returns False.
Console.WriteLine(false ^ false);
// When both operands are true, exclusive-OR returns False.
Console.WriteLine(true ^ true);
有关运算符的更多信息@https://msdn.microsoft.com/en-us/library/0zbsw2z6.aspx & https://msdn.microsoft.com/en-us/library/zkacc7k1.aspx
C#中的^ operator is a boolean logical operator, it's purpose is to perfom the Exclusive or (XOR)操作。
对于 bool 操作数,只有当两个操作数之一为真时,此操作的结果才会 return 真,这意味着:
true ^ true // Will return false
false ^ false // Will return false
true ^ false // Will return true
对于整数操作数,它执行按位异或,示例(括号中显示二进制表示):
1 (1) ^ 1 (1) // Will return 0 (0)
0 (0) ^ 0 (0) // Will return 0 (0)
1 (1) ^ 0 (0) // Will return 1 (1)
2 (10) ^ 1 (1) // Will return 3 (11)
15 (1111) ^ 5 (101) // Will return 10 (1010)
^= operator 将对左右操作数执行相同的操作,这意味着 x ^= y 与 x = x ^ y 相同。
异或的道理table可以帮助理解:
A B Result
0 0 0
0 1 1
1 0 1
1 1 0