I changed binary2Hex and Hex2Binary parts to make a bit more efficient :) I am using the code above at the moment, it is trusted to be worked.
private string HexToBinary(string hexString)
{
string binaryval = String.Empty;
for (int i = 0; i < hexString.Length; i = i + 2)
{
binaryval += Convert.ToString(Convert.ToInt32(hexString.Substring(i, 2), 16), 2).PadLeft(8, '0');
}
return binaryval;
}
private string BinaryToHex(string binString)
{
string hexval = String.Empty;
for (int i = 0; i < binString.Length; i = i + 8)
{
hexval += Convert.ToString(Convert.ToInt32(binString.Substring(i, 8), 2), 16).PadLeft(2, '0');
}
return hexval;
}
private string XORStrings(string s1, string s2)
{
string bin1 = HexToBinary(s1);
string bin2 = HexToBinary(s2);
string result = String.Empty;
for (int i = 0; i < bin1.Length; i++)
{
if (bin1\[i\] == bin2\[i\])//either both 0 or both 1
result += "0";
else //both are different i.e. 1 and 0 or 0 and 1
result += "1";
}
return BinaryToHex(result);
}