Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

isxdigit — C23 character classification function

`isxdigit(c)` from `<ctype.h>` returns nonzero for a hexadecimal digit: `0`–`9`, `A`–`F`, or `a`–`f`. It classifies one character; it does not parse a complete literal or its `0x` prefix.

Version: C23

Syntax

int isxdigit(int c);

isxdigit(c) from <ctype.h> returns nonzero for a hexadecimal digit: 0–9, A–F, or a–f. It classifies one character; it does not parse a complete literal or its 0x prefix.

The example tests A, f, G, and 9, normalizing results with != 0. Output 1 1 0 1 demonstrates both letter cases, the boundary beyond F, and a decimal digit.

The argument must be EOF or representable as unsigned char; a negative plain char has undefined behavior. For a byte use isxdigit((unsigned char)ch). The function checks neither sign, prefix, nor numeric overflow; after validating a string use strtoul with end-pointer and errno checks.

Examples

#include <ctype.h>
#include <stdio.h>

int main(void) {
    int values[] = {'A', 'f', 'G', '9'};
    printf("%d %d %d %d\n", isxdigit(values[0]) != 0, isxdigit(values[1]) != 0, isxdigit(values[2]) != 0, isxdigit(values[3]) != 0);
    return 0;
}

Result

1 1 0 1

The example tests `A`, `f`, `G`, and `9`, normalizing results with `!= 0`. Output `1 1 0 1` demonstrates both letter cases, the boundary beyond `F`, and a decimal digit.

Sources