字节数组与字符串形式的数字(序列号)之间的相互转换

 1 //将字节转换成字符串
 2 public static string Card_Bytes2String(byte[] bCard)
 3 {
 4     if (bCard.Length != 8)
 5     {
 6          throw new ApplicationException("不是有效的数据!");
 7     }
 8 
 9      string scard = "";
10 
11      for (int i = 0; i < bCard.Length; i++)
12      {
13           scard += string.Format("{0:X2}", bCard[i]);
14      }
15 
16       return scard;
17 }
 1 //将字符串转化成字节数组
 2 public static byte[] Card_String2Bytes(string bCard)
 3 {
 4     byte[] scard = new byte[8];
 5 
 6     for (int i = 0; i < 8; i++)
 7     {
 8         scard[i] = Convert.ToByte("0X" + bCard.Substring(i * 2, 2), 16);
 9     }
10 
11     return scard;
12 
13 }
原文地址:https://www.cnblogs.com/wynblogscc/p/13533974.html