zoukankan      html  css  js  c++  java
  • 字符串转16进制字节数组,字节数组转16进制字符串

            /// <summary>
            /// 字符串转16进制字节数组
            /// </summary>
            /// <param name="hexString"></param>
            /// <returns></returns>
            public static byte[] Str_ToHexByte(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;
            }
    
            /// <summary>
            /// 字节数组转16进制字符串
            /// </summary>
            /// <param name="bytes"></param>
            /// <returns></returns>
            public static string Str_ToHexString(byte[] bytes)
            {
                string returnStr = "";
                if (bytes != null)
                {
                    for (int i = 0; i < bytes.Length; i++)
                    {
                        returnStr = returnStr + bytes[i].ToString("X2") + " ";
                    }
                }
                return returnStr;
            }
  • 相关阅读:
    E
    J
    D
    并查集加优先队列
    动态规划-数位DPwindy
    动态规划-分组背包问题
    动态规划-LIS1
    动态规划-01背包
    [cf1434E]A Convex Game
    [atAGC106F]Figures
  • 原文地址:https://www.cnblogs.com/bdf216/p/3467492.html
Copyright © 2011-2022 走看看