Austin Ehlers said:
byte[] bytes;
/.../
string hexed="";
foreach(byte b in bytes)
hexed+=b.ToString("x2");
When you're going through a loop appending text and you don't know at
compile-time that the loop won't be repeated more than a few times, you
should always use a StringBuilder. In this case, you even know the
capacity the StringBuilder should use:
byte[] bytes;
/*...*/
StringBuilder sb = new StringBuilder(bytes.Length*2);
foreach (byte b in bytes)
{
sb.AppendFormat ("{0:x2}", b);
}
string result = sb.ToString();
For a 40K array, this makes the difference between taking over 6
seconds on my box, and under a 20th of a second.