S
semedao
Hi , I try the BitArray class to make Xor on 2 byte arrays.
The result was that when I Xor 1with 2 I get 3 which is correct
then Xoring 3 with 1 give me 0 (zero) when it should give me 2 !
but Xoring 3 with 2 give 2 which is correct... (should be 1)
here is the sample code...
BitArray ba1, ba2, ba3 , ba4;
Int64 i1,i2,i3,i4;
i1 = 1;
i2 = 2;
byte[] b1,b2,b3,b4;
b1 = BitConverter.GetBytes(i1);
b2 = BitConverter.GetBytes(i2);
ba1 = new BitArray(b1);
ba2 = new BitArray(b2);
b3 = new byte[Math.Max(b1.Length, b2.Length)];
b4 = new byte[Math.Max(b1.Length, b2.Length)];
ba3 = ba1.Xor(ba2);
ba3.CopyTo(b3, 0);
String s1 = BitConverter.ToInt64(b3, 0).ToString();
BitArray ba4 = ba3.Xor(ba1);
ba4.CopyTo(b4, 0);
String s2 = BitConverter.ToInt64(b4,0).ToString();
ba4 = ba3.Xor(ba2);
ba4.CopyTo(b4, 0);
String s3 = BitConverter.ToInt64(b4, 0).ToString();
The result was that when I Xor 1with 2 I get 3 which is correct
then Xoring 3 with 1 give me 0 (zero) when it should give me 2 !
but Xoring 3 with 2 give 2 which is correct... (should be 1)
here is the sample code...
BitArray ba1, ba2, ba3 , ba4;
Int64 i1,i2,i3,i4;
i1 = 1;
i2 = 2;
byte[] b1,b2,b3,b4;
b1 = BitConverter.GetBytes(i1);
b2 = BitConverter.GetBytes(i2);
ba1 = new BitArray(b1);
ba2 = new BitArray(b2);
b3 = new byte[Math.Max(b1.Length, b2.Length)];
b4 = new byte[Math.Max(b1.Length, b2.Length)];
ba3 = ba1.Xor(ba2);
ba3.CopyTo(b3, 0);
String s1 = BitConverter.ToInt64(b3, 0).ToString();
BitArray ba4 = ba3.Xor(ba1);
ba4.CopyTo(b4, 0);
String s2 = BitConverter.ToInt64(b4,0).ToString();
ba4 = ba3.Xor(ba2);
ba4.CopyTo(b4, 0);
String s3 = BitConverter.ToInt64(b4, 0).ToString();