1 /// <summary> 2 /// 轉換擴展類 3 /// </summary> 4 public static class ConvertExtend 5 { 6 /// <summary> 7 /// 將byte[]轉換為16進位字元串 8 /// </summary> 9 /// <p ...
1 /// <summary> 2 /// 轉換擴展類 3 /// </summary> 4 public static class ConvertExtend 5 { 6 /// <summary> 7 /// 將byte[]轉換為16進位字元串 8 /// </summary> 9 /// <param name="bytes"></param> 10 /// <returns></returns> 11 public static string ToString16(this byte[] bytes) 12 { 13 return bytes.ToList().ToString16(); 14 } 15 16 /// <summary> 17 /// 將List<byte>轉換為16進位字元串 18 /// </summary> 19 /// <param name="bytes"></param> 20 /// <returns></returns> 21 public static string ToString16(this List<byte> bytes) 22 { 23 return string.Join(" ", bytes.ConvertAll(b => Convert.ToString(b, 16))); 24 } 25 26 /// <summary> 27 /// 將16進位字元串轉換為byte[] 28 /// </summary> 29 /// <param name="str16"></param> 30 /// <returns></returns> 31 public static byte[] ToByte(this string str16) 32 { 33 return str16.Split(' ').ToList().ConvertAll(s => Convert.ToByte(s, 16)).ToArray(); 34 } 35 }ConvertExtend