如何将十进制值转换为AScii,我已经尝试过
var charStrs = Convert.ToString(receivedEvent.tagData.can_Msg.data[3]) +
Convert.ToString(receivedEvent.tagData.can_Msg.data[4]) +
Convert.ToString(receivedEvent.tagData.can_Msg.data[5]) +
Convert.ToString(receivedEvent.tagData.can_Msg.data[6]) +
Convert.ToString(receivedEvent.tagData.can_Msg.data[7]);
var asStr = String.Concat(charStrs.Select(cs => (char)Int32.Parse(cs, NumberStyles.HexNumber)));
我知道我的十进制数= 56 49 50 48 48 48 53 56 50 56,当将其转换为ascii时,我将得到8120005828;但我在NumberStyles.HexNumber中出现错误,它似乎无法在wpf上运行?
答案 0 :(得分:4)
我不确定data[3]
等中的值是多少,但来自http://www.asciitable.com/
int[] values = { 56, 49, 50, 48, 48, 48, 53, 56, 50, 56 };
char[] chars = values.Select(x => (char)x).ToArray();
string str = new string(chars);
Console.WriteLine(str); // "8120005828"
您的部分问题可能是那些是十进制数字,但您尝试将它们解析为十六进制数字。
答案 1 :(得分:0)
data[0] = ((char)(Int32.Parse(data[0], NumberStyles.HexNumber))).ToString();
Console.WriteLine(data.Aggregate((s1, s2) => s1 + (char)(Int32.Parse(s2, NumberStyles.HexNumber))) );
这适用于您的场景