Skip to content

Commit 463ec5d

Browse files
committed
Apply Tanner's suggested changes
1 parent 22b1e8a commit 463ec5d

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/libraries/Common/src/System/HexConverter.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,28 @@ public static unsafe string ToString(ReadOnlySpan<byte> bytes, Casing casing = C
107107
public static char ToCharUpper(int value)
108108
{
109109
value &= 0xF;
110-
return (char)(value > 9 ? value - 10 + 'A' : value + '0');
110+
value += '0';
111+
112+
if (value > '9')
113+
{
114+
value += ('A' - '0');
115+
}
116+
117+
return (char)value;
111118
}
112119

113120
[MethodImpl(MethodImplOptions.AggressiveInlining)]
114121
public static char ToCharLower(int value)
115122
{
116123
value &= 0xF;
117-
return (char)(value > 9 ? value - 10 + 'a' : value + '0');
124+
value += '0';
125+
126+
if (value > '9')
127+
{
128+
value += ('a' - '0');
129+
}
130+
131+
return (char)value;
118132
}
119133
}
120134
}

0 commit comments

Comments
 (0)