using System; using System.Collections.Generic; using System.Windows.Forms; namespace FileAnalysis { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Analysis_Click(object sender, EventArgs e) { Result.Clear(); int[] list = GetDecimalData(ReturnData.Text, new int[] { 8, 8, 4, 4, 4, 4, 8, 8, 8, 8, 8, 8, 8, 4, 4, 4, 4, 4, 4 }, new int[] { 6 }); for (int i = 0; i < list.Length; i++) { Result.AppendText(list[i] + "\n"); } } public static int[] GetDecimalData(string HexStr, int[] DataSize, int[] NotShow) { List ReturnData = new List(); try { //去除前面的指令字符和数据长度字符 HexStr = HexStr.Replace(":", ""); if (HexStr != "") { int ValueDataSize = Convert.ToInt32("0x" + (HexStr.Substring(4, 2)), 16) * 2; string RealData = HexStr.Substring(6); RealData = RealData.Substring(0, ValueDataSize); int SubIndex = 0; for (int i = 0; i < DataSize.Length; i = i + 1) { if (SubIndex + DataSize[i] < RealData.Length) { bool notshow = false; for (int j = 0; j < NotShow.Length; j++) { if (i == NotShow[j]) notshow = true; } if (notshow) { SubIndex += DataSize[i]; continue; } if (DataSize[i] == 8) { Console.WriteLine("0x" + (RealData.Substring(SubIndex, DataSize[i]).Substring(4, 4)) + (RealData.Substring(SubIndex, DataSize[i]).Substring(0, 4))); ReturnData.Add(Convert.ToInt32("0x" + (RealData.Substring(SubIndex, DataSize[i]).Substring(4, 4)) + (RealData.Substring(SubIndex, DataSize[i]).Substring(0, 4)), 16)); } else if (DataSize[i] == 4) { Console.WriteLine("0x" + (RealData.Substring(SubIndex, DataSize[i]))); ReturnData.Add(Convert.ToInt32("0x" + (RealData.Substring(SubIndex, DataSize[i])), 16)); } } SubIndex += DataSize[i]; } } } catch (Exception ex) { Console.WriteLine(ex.Message); } return ReturnData.ToArray(); } private void Form1_Load(object sender, EventArgs e) { } } }