/// <summary> /// 一组十六进制的字符串每两个转成对应值的byte,比如4142 会成 AB对应的byte列表 /// </summary> /// <param name="hexString"></param> /// <returns></returns> static List<byte> HexStringToBytes(string hexString) { if (hexString.Length % 2 != 0) return null; List<byte> result = new List<byte>(); for (int i = 0; i < hexString.Length; i = i + 2) { byte v = Convert.ToByte(hexString[i].ToString(), 16); v <<= 4; v += Convert.ToByte(hexString[i + 1].ToString(), 16); result.Add(v); } return result; //return result; }
private string ByteToString(byte[] bytes) { StringBuilder sb = new StringBuilder(); foreach (var temp in bytes) { sb.Append(temp.ToString("X2")); } return sb.ToString(); }