What is isxdigit in C?

The isxdigit function in C checks whether a character is a hexadecimal digit. Hexadecimal digits include the numbers 090-9, uppercase letters AFA-F, and lowercase letters afa-f.

To use the isxdigit function, you will need to include the <ctype.h> library in the program, as shown below:

#include <ctype.h>

The prototype of the isxdigit function is shown below:

int isxdigit(int c);

Parameters

The isxdigit function takes a single mandatory parameter, i.e., an integer that represents the character you want to check.

Note: In the C language, characters are treated as integer values.

Return Value

If the argument passed to the isxdigit function is a valid hexadecimal character, then the function returns a non-zero integer; otherwise, it returns 00.

Example

The code below shows how the isxdigit function works in C:

#include <stdio.h>
#include <ctype.h>
#include <string.h>
int main() {
// initializing string
char str[] = "ae2k3F9J";
// extracting characters
for(int i = 0; i < strlen(str); i++)
{
// hexadecimal check
if(isxdigit(str[i]))
{
printf("\'%c\' is a hexadecimal digit.\n", str[i]);
}
else
{
printf("\'%c\' is not a hexadecimal digit.\n", str[i]);
}
}
return 0;
}

Explanation

First, the code initializes a character array. A for-loop iterates over the length of this array and extracts each character.

Each extracted character is then provided as an argument to the isxdigit function on line 15.

The isxdigit function proceeds to check if the character is a valid hexadecimal digit and outputs the result accordingly.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved