In C#, Char.IsAsciiHexDigit returns true for hexadecimal digit characters: 0–9, A–F, and a–f.
These ASCII helpers are available in .NET 7 and later. On older runtimes, use range checks such as c >= '0' && c <= '9'.
This is a static member of System.Char. You call it with the type name, such as Char.IsAsciiHexDigit(...) or char.IsAsciiHexDigit(...). A char holds one 16-bit UTF-16 code unit.
Syntax
Pass a potential hex digit.
C#
bool ok = Char.IsAsciiHexDigit('B');
Call
What it does
Char.IsAsciiHexDigit(c)
True for 0–9, A–F, a–f.
Use Lower/Upper variants to restrict case.
Library declarations
C#
public static bool IsAsciiHexDigit(char c);
Parameters
Parameter
Description
c
Character to test.
Return Value
Return Value
Description
true
ASCII hex digit.
false
Not a hex digit.
C# Examples
Example 1 — Hex Letters
Test B, g, and G.
C#
using System;
class Program {
static void Main() {
Console.WriteLine(Char.IsAsciiHexDigit('B'));
Console.WriteLine(Char.IsAsciiHexDigit('g'));
Console.WriteLine(Char.IsAsciiHexDigit('G'));
}
}
Output
True
False
False
How It Works
B is hex. Within A–F.
g fails. Beyond f.
G fails. Beyond F.
Case variants. a–f and A–F both work; g/G do not.
Example 2 — Numeric Hex
Digits count as hex too.
C#
using System;
class Program {
static void Main() {
Console.WriteLine(Char.IsAsciiHexDigit('9'));
Console.WriteLine(Char.IsAsciiHexDigit('a'));
}
}
Output
True
True
How It Works
Nine. 0–9 are hex digits.
Lower a. a–f accepted.
Both true. Common hex alphabet.
Color codes. Useful for #RRGGBB validation.
Example 3 — Check a Hex Byte
Validate two hex characters.
C#
using System;
class Program {
static void Main() {
string pair = "FF";
bool ok = Char.IsAsciiHexDigit(pair[0]) && Char.IsAsciiHexDigit(pair[1]);
Console.WriteLine(ok);
}
}
Output
True
How It Works
Two chars. FF as a hex byte text.
Both checked. Index 0 and 1 must pass.
True. F is a valid hex letter.
Building blocks. Extend to longer hex strings the same way.