日期:2014-05-18 浏览次数:20934 次
int[] arr = new int[] { 0x11, 0x02, 0x03, 0xff }; string s = ""; foreach (int i in arr) { s += Convert.ToString(i, 16).PadLeft(2,'0'); } MessageBox.Show(s);
------解决方案--------------------
byte[] arr = new byte[1024]; arr[0] = 0x11; arr[1] = 0x02; arr[2] = 0x03; arr[3] = 0xff; string s = ""; for (int i = 0; i < arr.Length && arr[i] > 0; i++) { s += arr[i].ToString("x2"); } 或者 string s = string.Join("", Array.ConvertAll(Array.FindAll(arr, o => o > 0), o => o.ToString("x2")));