📄 form1.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
public static byte[] StringToByte(string InString)
{
string[] ByteStrings;
ByteStrings = InString.Split(" ".ToCharArray());
byte[] ByteOut;
ByteOut = new byte[ByteStrings.Length];
for (int i = 0; i < ByteStrings.Length; i++)
{
//byte x = Convert.ToByte(("0x" + ByteStrings[i]));
//ByteOut[i] = Convert.ToByte(("0x" + ByteStrings[i]), 16);
ByteOut[i] = Convert.ToByte(ByteStrings[i], 16);
}
return ByteOut;
}
private string strTextTostrBin(string strText)
{
byte[] bytearr = null;
string stringtobin = "";
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
bytearr = encoding.GetBytes(strText);
for (int i = 0; i < bytearr.Length; i++)
{
stringtobin += "," + bytearr[i].ToString();
}
return stringtobin.Substring(1);
}
private string strBinTostrText(string strBin)
{
string[] bintostr = strBin.Split(',');
Array binArray = Array.CreateInstance(Type.GetType("System.Byte"), bintostr.Length);
for (int i = binArray.GetLowerBound(0); i <= binArray.GetUpperBound(0); i++)
{
binArray.SetValue(byte.Parse(bintostr[i] + ""), i);
}
byte[] strtobin = new byte[bintostr.Length];
for (int i = binArray.GetLowerBound(0); i <= binArray.GetUpperBound(0); i++)
{
strtobin[i] = (byte)binArray.GetValue(i);
}
System.Text.Encoding encoding = System.Text.Encoding.UTF8;
return encoding.GetString(strtobin);
}
//byte[] buf;
private void button1_Click(object sender, EventArgs e)
{
// buf = StringToByte("01 FF");
textBox1.Text = strTextTostrBin(textBox3.Text);
textBox2.Text = strBinTostrText(textBox1.Text);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -