View on GitHub qJake's

Tidbits

Bits of development knowledge from experience and headache.

Convert a Byte Array to a Hex String

Posted on: Saturday, February 27, 2016

Often times (most notably during hashing/encrypting), you’ll have a byte[] but want a string of hex values.

There are a lot of ways to solve this problem, some much more performant than others. If performance isn’t a huge issue, I always prefer this one-liner, which is mentioned in the post. I also like to make it an extension method for easier use.

public static string ToHexString(this byte[] bytes)
{
    return BitConverter.ToString(bytes).Replace("-", "");
}