【C#】字符串字节转16进制字节数组

public static byte[] ConvertStringToBytes(String str)
{
    List<byte> listBytes = new List<byte>();
    string[] hexValuesSplit = str.Trim().Split(' ');
    foreach (string hex in hexValuesSplit)
    {
        listBytes.Add(Convert.ToByte(hex, 16));
    }
    return listBytes.ToArray();
}
posted @ 2024-05-20 11:10  qiutian-hao  阅读(62)  评论(0编辑  收藏  举报