下面是代码(十六进制转换为十进制)我正在努力解决.. 我发现了错误,我在代码中已经注释了位置..C#编码:十六进制到十进制&字符编码
请提供一个解决方案,以纠正..
static void Main(string[] args)
{
byte[] byteData;
int n;
byteData = GetBytesFromHexString("001C0014500C0A5B06A4FFFFFFFFFFFFFFFFFFFFFFFFFFFF");
n = byteData.Length;
Console.WriteLine(n);
string s = System.Text.Encoding.UTF8.GetString(byteData, 0, n); //error
Console.WriteLine(s);
Console.ReadLine();
}
public static byte[] GetBytesFromHexString(string hexString)
{
//MessageBox.Show("getbytes ");
if (hexString == null)
return null;
if (hexString.Length % 2 == 1)
hexString = '0' + hexString; // Up to you whether to pad the first or last byte
byte[] data = new byte[hexString.Length/2];
for (int i = 0; i < data.Length; i++)
{
data[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
Console.WriteLine(data[i]);
}
什么我得到的输出是: “\ 0 \ 0 P \˚F\ n [ “ 转换后的十进制值未被编码。
UPDATE: 预期输出为 “0 28 0 20 80 12 10 91 6 164 255 255 255 255 255 255 255 255 255 255 255 255 255 255”
你从'Console.WriteLine(S)有什么期望输出;'? –
检查此链接 http://stackoverflow.com/questions/74148/how-to-convert-numbers-between-hexadecimal-and-decimal-in-c –
我得到System.Byte []这是没有得到编码.. – user3222857