十六进制字符串Hex转byte数组

 public static byte[] HexStringTobyte(this 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).Trim(), 16);
            return returnBytes;
        }

 

posted on 2020-07-01 14:39  跨界农民工  阅读(2311)  评论(0编辑  收藏  举报

导航