private void button2_Click(object sender, EventArgs e)
{
string str_text_string= textBox1.Text.ToString();
byte[] by= ConvertToByte(str_text_string);
string str_byte_string = ConvertToString(by);
label1.Text = str_text_string;
}
//字符串转二进制:
private byte[] ConvertToByte(string theString)
{
byte[] byteStream = System.Text.Encoding.Default.GetBytes(theString);
return byteStream;
}
//二进制转字符串:
private string ConvertToString(byte[] thebyte)
{
char[] Chars = new char[System.Text.Encoding.Default.GetCharCount(thebyte, 0, thebyte.Length)];
System.Text.Encoding.Default.GetChars(thebyte, 0, thebyte.Length, Chars, 0);
string newString = new string(Chars);
return newString;
}
{
string str_text_string= textBox1.Text.ToString();
byte[] by= ConvertToByte(str_text_string);
string str_byte_string = ConvertToString(by);
label1.Text = str_text_string;
}
//字符串转二进制:
private byte[] ConvertToByte(string theString)
{
byte[] byteStream = System.Text.Encoding.Default.GetBytes(theString);
return byteStream;
}
//二进制转字符串:
private string ConvertToString(byte[] thebyte)
{
char[] Chars = new char[System.Text.Encoding.Default.GetCharCount(thebyte, 0, thebyte.Length)];
System.Text.Encoding.Default.GetChars(thebyte, 0, thebyte.Length, Chars, 0);
string newString = new string(Chars);
return newString;
}