Unify int to hexadecimal char conversions by marek-safar · Pull Request #1273 · dotnet/runtime (original) (raw)
private static ReadOnlySpan HexEncodeUpper => new byte [] { (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'A', (byte)'B', (byte)'C', (byte)'D', (byte)'E', (byte)'F' }; private static ReadOnlySpan HexEncodeLower => new byte [] { (byte)'0', (byte)'1', (byte)'2', (byte)'3', (byte)'4', (byte)'5', (byte)'6', (byte)'7', (byte)'8', (byte)'9', (byte)'a', (byte)'b', (byte)'c', (byte)'d', (byte)'e', (byte)'f' };
public static char ToCharUpper(int value) => (char)HexEncodeUpper[value & 0xF]; public static char ToCharLower(int value) => (char)HexEncodeLower[value & 0xF];
? (Especially once the JIT properly removes the bounds check on this, if it doesn't already.)