Converts all bytes in the Array to a string representation. - CSharp System

CSharp examples for System:Byte Array

Description

Converts all bytes in the Array to a string representation.

Demo Code


using System.Text;
using System.Security.Cryptography;

public class Main{
        #endif/*from   w ww .ja  v  a  2 s .  com*/

        /// <summary>
        ///   Converts all bytes in the Array to a string representation.
        /// </summary>
        /// <param name="buf"> </param>
        /// <returns> string representation </returns>
        public static string HexToString(byte[] buf)
        {
            var sb = new StringBuilder();
            foreach (byte b in buf)
            {
                sb.Append(b.ToString("x2"));
            }

            return sb.ToString();
        }
}

Related Tutorials