How to convert a byte array to a hexadecimal string in C#?
To convert a byte array to hexadecimal string in C# we can simply convert byte array to string using methodBitConverter.ToString()
and finally remove hyphen.Example
using System;
public class Example
{
public static void Main()
{
byte[] smallArray = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 };
string result = BitConverter.ToString(smallArray).Replace("-","");
Console.WriteLine(result);
}
}
Output
20202020202020