您可以使用此代码将字节 [] 转换为十六进制字符串
将您的 char[] 转换为 byte[] 或根据需要修改代码:)
/// <summary>
/// Converts a byte array to a hex string. For example: {10,11} = "0A 0B"
/// </summary>
public static string ByteToHex(byte[] data)
{
StringBuilder sb = new StringBuilder();
foreach (byte b in data)
{
string hex = ByteToHex(b);
sb.Append(hex);
sb.Append(" ");
}
if (sb.Length > 0)
sb.Remove(sb.Length - 1, 1);
return sb.ToString();
}
/// <summary>
/// Converts the byte to a hex string. For example: "10" = "0A";
/// </summary>
public static string ByteToHex(byte b)
{
string sB = b.ToString(ConstantReadOnly.HexStringFormat, CultureInfo.InvariantCulture);
if (sB.Length == 1)
sB = "0" + sB;
return sB;
}