如何字符转换成16进制
String.format( "{0:X}{1:x2} ",s,t);
请问要如何写{0:??}才能转换成十六进制, 以及转换成二进制.
------解决方案--------------------for example:
string str = "A ";
int i = Convert.ToInt32(str,16);
Console.WriteLine(Convert.ToString(i, 16));
Console.WriteLine(Convert.ToString(i, 2));
------解决方案--------------------用Encoding把字符先转换成byte,然后用ToString( "X " ) or ToString( "X2 ")进行输出即可。
------解决方案--------------------private void button5_Click(object sender, EventArgs e)
{
Encoding vEncoding = Encoding.ASCII;
string S = "12345678 ";
byte[] vBuffer = vEncoding.GetBytes(S);
StringBuilder vBuilder = new StringBuilder(S.Length * 2);
for (int i = 0; i < vBuffer.Length; i++)
{
vBuilder.Append(vBuffer[i].ToString( "x2 "));
}
Text = vBuilder.ToString();
}