亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#操作Byte數(shù)組和十六進(jìn)制進(jìn)行互轉(zhuǎn)

 更新時(shí)間:2022年05月02日 15:17:12   作者:農(nóng)碼一生  
這篇文章介紹了C#操作Byte數(shù)組和十六進(jìn)制進(jìn)行互轉(zhuǎn)的的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

一、Byte 數(shù)組轉(zhuǎn)十六進(jìn)制字符串

 		/// <summary>
        /// Byte 數(shù)組轉(zhuǎn)十六進(jìn)制字符串
        /// </summary>
        /// <param name="Bytes"></param>
        /// <returns></returns>
        public static string ByteToHex(byte[] Bytes)
        {
            string str = string.Empty;
            foreach (byte Byte in Bytes)
            {
                str += String.Format("{0:X2}", Byte) + " ";
            }
            return str.Trim();
        }

二、字符串轉(zhuǎn)十六進(jìn)制Byte數(shù)組

        /// <summary>
        /// 字符串轉(zhuǎn)十六進(jìn)制Byte數(shù)組
        /// </summary>
        /// <param name="hexString"></param>
        /// <returns></returns>
        public static byte[] strToToHexByte(string hexString)
        {
            try
            {
                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;
            }
            catch
            {
                return null;
            }

        }

到此這篇關(guān)于C#操作Byte數(shù)組和十六進(jìn)制進(jìn)行互轉(zhuǎn)的文章就介紹到這了。希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論