【C#】字符串字节转字节数组

public static byte[] strToToHexByte(string hexString)
{
    hexString = hexString.Replace(" ", "");

    if ((hexString.Length % 2) != 0)

        hexString += " ";

    byte[] returnBytes = new byte[hexString.Length / 2];

    for (int i = 0; i < returnBytes.Length; i++)

        returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);

    return returnBytes;

}
posted @ 2024-03-19 11:35  qiutian-hao  阅读(33)  评论(0编辑  收藏  举报