Created
July 14, 2014 16:37
-
-
Save mlehmk/3d53758765d0e96cf4fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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