如何在C#中对二进制进行异或运算? [英] how to binary xor binary in C#?
本文介绍了如何在C#中对二进制进行异或运算?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
this my code:
public static string StringToBinary(string data)
{
StringBuilder sb = new StringBuilder();
foreach (char c in data.ToCharArray())
{
sb.Append(Convert.ToString(c, 2).PadLeft(8, '0'));
}
return sb.ToString();
}
private void button12_Click(object sender, EventArgs e)
{
string plainText = "a"+textBox3.Text;
string keyText = textBox4.Text;
string binaryplain = StringToBinary(plainText);
string binarykey = StringToBinary(keyText);
int int1 = Convert.ToInt32(binaryplain, 2); //this trouble : Value was either too large or too small for a UInt32.
int int2 = Convert.ToInt32(binarykey, 2);
int int3 = int1 ^ int2;
string hasil = Convert.ToString(int3,2);
textBox5.Text = hasil;
}
请帮助我...
please help me...
推荐答案
由于您尚未指定问题所在,您仍然可以查看以下链接以获取解决问题的方法.
http://msdn.microsoft.com/en-us/library/zkacc7k1.aspx [ ^ ]
了解按位运算符的工作方式(C#和VB.NET示例) [ ^ ]
http://www.dotnetperls.com/xor [
As you have not specified what the problem is, still you can look at following links to get the solution of your problem.
http://msdn.microsoft.com/en-us/library/zkacc7k1.aspx[^]
Understand how bitwise operators work (C# and VB.NET examples)[^]
http://www.dotnetperls.com/xor[^]
-KR
这篇关于如何在C#中对二进制进行异或运算?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文