C# byte数组转换成字符串

快乐鱼儿 1年前 ⋅ 1043 阅读
        /// <summary>
        /// byte数组转换成字符串
        /// </summary>
        /// <param name="bArray"></param>
        /// <returns></returns>
        public string convertByteToString(byte[] bArray)
        {
            string sResult = "";

            try
            {
                for (int i = 0; i < bArray.Length; i++)
                {
                    if (((UInt32)bArray[i]) <= 0xF)
                    {
                        sResult += "0" + string.Format("{0:X}", bArray[i]);
                    }
                    else
                    {
                        sResult += string.Format("{0:X}", bArray[i]);
                    }
                }
                return sResult;
            }
            catch (Exception exp)
            {
                throw exp;
            }
        }

全部评论: 0

    我有话说: