Converts array of bytes into HEX-encoded string. - CSharp System

CSharp examples for System:Byte Array

Description

Converts array of bytes into HEX-encoded string.

Demo Code


using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;//  w w  w  .j a v a2 s .c o m

public class Main{
        /// <summary>
    ///   <para>Converts array of bytes into HEX-encoded string.</para>
    /// </summary>
    /// <param name="self">Bytes to convert to HEX string.</param>
    /// <returns>HEX string representation of <paramref name="self"/> array.</returns>
    /// <exception cref="ArgumentNullException">If <paramref name="self"/> is a <c>null</c> reference.</exception>
    /// <seealso cref="BitConverter.ToString(byte[])"/>
    /// <seealso cref="StringExtensions.Hex(string)"/>
    public static string Hex(this byte[] self)
    {
      Assertion.NotNull(self);

      return BitConverter.ToString(self).Replace("-", "");
    }
}

Related Tutorials