C# Char IsAsciiHexDigit() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Char

Definition

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');
CallWhat 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

ParameterDescription
cCharacter to test.

Return Value

Return ValueDescription
trueASCII hex digit.
falseNot 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'));
    }
}

How It Works

  1. B is hex. Within A–F.
  2. g fails. Beyond f.
  3. G fails. Beyond F.
  4. 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'));
    }
}

How It Works

  1. Nine. 0–9 are hex digits.
  2. Lower a. a–f accepted.
  3. Both true. Common hex alphabet.
  4. 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);
    }
}

How It Works

  1. Two chars. FF as a hex byte text.
  2. Both checked. Index 0 and 1 must pass.
  3. True. F is a valid hex letter.
  4. Building blocks. Extend to longer hex strings the same way.

Frequently Asked Questions

A–F and a–f, plus digits 0–9.
No.
.NET 7+.
IsAsciiHexDigitLower and IsAsciiHexDigitUpper.
This helper is ASCII-only.

Next: IsAsciiHexDigitLower()

Return true for ASCII hex digits 0–9 and a–f (lowercase). .NET 7+ with System.Char.

IsAsciiHexDigitLower() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful