<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="10.0.0-preview.6.25358.103" />

HexConverter

static class HexConverter
using System.Runtime.CompilerServices; namespace System { internal static class HexConverter { public enum Casing : uint { Upper = 0, Lower = 8224 } public unsafe static ReadOnlySpan<byte> CharToHexLookup => new ReadOnlySpan<byte>(&global::<PrivateImplementationDetails>.21244F82B210125632917591768F6BF22EB6861F80C6C25A25BD26DFB580EA7B, 256); [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void ToCharsBuffer(byte value, Span<char> buffer, int startingIndex = 0, Casing casing = Casing.Upper) { uint num = (uint)(((value & 240) << 4) + (value & 15) - 35209); uint num2 = (uint)((int)((((0 - num) & 28784) >> 4) + num + 47545) | (int)casing); buffer[startingIndex + 1] = (char)(num2 & 255); buffer[startingIndex] = (char)(num2 >> 8); } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int FromChar(int c) { ReadOnlySpan<byte> charToHexLookup = CharToHexLookup; if (c < charToHexLookup.Length) { charToHexLookup = CharToHexLookup; return charToHexLookup[c]; } return 255; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static int FromLowerChar(int c) { if ((uint)(c - 48) <= 9) return c - 48; if ((uint)(c - 97) <= 5) return c - 97 + 10; return 255; } [MethodImpl(MethodImplOptions.AggressiveInlining)] public static bool IsHexLowerChar(int c) { if ((uint)(c - 48) > 9) return (uint)(c - 97) <= 5; return true; } } }