Skip to content

Instantly share code, notes, and snippets.

@rquackenbush
Created October 27, 2017 16:16
Show Gist options
  • Save rquackenbush/72d7294fc8b6f71b3ec949129a239cd1 to your computer and use it in GitHub Desktop.
Save rquackenbush/72d7294fc8b6f71b3ec949129a239cd1 to your computer and use it in GitHub Desktop.
Hex formatter
using System.Text;
namespace CaptiveAire.Scada.Module.Base.Extensions
{
public static class ArrayExtensions
{
public static string ToHex(this byte[] bytes, bool upperCase = false)
{
StringBuilder result = new StringBuilder(bytes.Length * 2);
foreach (byte b in bytes)
{
result.Append(b.ToString(upperCase ? "X2" : "x2"));
}
return result.ToString();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment