This is a question similar to this one here.
Is there a built-in method that converts an array of byte to hex string? More specifically, I’m looking for a built in function for
/// <summary>
/// Convert bytes in a array Bytes to string in hexadecimal format
/// </summary>
/// <param name="Bytes">Bytes array</param>
/// <param name="Length">Total byte to convert</param>
/// <returns></returns>
public static string ByteToHexString(byte[] Bytes, int Length)
{
Debug.Assert(Length <= Bytes.GetLength(0));
StringBuilder hexstr = new StringBuilder();
for (int i = 0; i < Length; i++)
{
hexstr.AppendFormat("{0,02:X}", Bytes[i]);
}
hexstr.Replace(' ', '0'); //padd empty space to zero
return hexstr.ToString();
}
Using BitConverter, ref: http://msdn.microsoft.com/en-us/library/bb311038.aspx