Skip to content

Instantly share code, notes, and snippets.

@mlehmk
Created July 14, 2014 16:37
Show Gist options
  • Save mlehmk/3d53758765d0e96cf4fa to your computer and use it in GitHub Desktop.
Save mlehmk/3d53758765d0e96cf4fa to your computer and use it in GitHub Desktop.
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]
private static char HexDigit(int p)
{
if (p < 10) return (char)(48 + p);
return (char)(87 + p);
}
public static string ToHexString(this byte[] ba)
{
char[] digits = new char[ba.Length * 2];
for (int i = 0; i < ba.Length; ++i)
{
int v = ba[i];
digits[i + i] = HexDigit(v >> 4);
digits[i + i + 1] = HexDigit(v & 0xF);
}
return new string(digits);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment