2016-04-17 1 views
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#でのために

を使用していますC#のコードでは、可変データをメインの の値に戻す方法、またはこの操作の反対のデータを戻す方法があります。data [i]^= Xor [xors];

+2

XORを* * XORの '反対' です。 '(a xor b)xor b == a' – Rob

+0

"C#^ operator"を検索しましたか? – Tibrogargan

+0

はい私は検索しましたが、バイナリでどのように動作するのか分かりませんでした –

答えて

3

C#で^ operatorboolean logical operatorです。その目的は、Exclusive or (XOR)操作を実行することです。 (

整数オペランドの
true^true // Will return false 
false^false // Will return false 
true^false // Will return true 

、それは、例をビット単位の排他的論理和を行うOR:ブールオペランドについては

、この操作の結果は、2つのオペランドのいずれかに該当する場合にのみ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と同じであることを意味し、左と右のオペランドと同じ操作を実行します。

XORの真理値表を理解するのに役立ちます:

 
A B Result
0 0 0
0 1 1
1 0 1
1 1 0
0

そのバイナリ演算子、バイナリ^演算子は整数型やブール

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); 

詳しい情報を可能にするものx = x^y

として評価されますオペレーター@https://msdn.microsoft.com/en-us/library/0zbsw2z6.aspx & https://msdn.microsoft.com/en-us/library/zkacc7k1.aspx

関連する問題