C isxdigit() Function Tutorial

In this section, we will learn what the isxdigit() function is and how to use it in C.

isxdigit() function in C

The `isxdigit()` function is used to check whether a character is a part of the characters supported in the hexadecimal digit.

Hexadecimal digits include these characters: 0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F

The prototype of the function exists in the `ctype.h` header file and we need to include this header file in order to use ` isxdigit ()` function.

isxdigit() Function Syntax

Here’s the prototype of the ` isxdigit ()` function:

int isxdigit (int argument);

isxdigit() Function Parameters

This function takes one argument and that is the character that we want to check.

isxdigit() Function Return Value

The return value of the function is:

  • 0: If the character was not in the list of characters supported in hexadecimal digit.
  • Positive value: if the character was in fact part of the characters supported in the hexadecimal digit.

Example: using isxdigit() function in C

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

int main() {

    char character = 'a';
    char c2 = '?';

    printf("The first character: %d \nThe second character: %d", isxdigit (character),isxdigit(c2));

    return  0;
}

Output:

The first character: 2

The second character: 0

The first character in this example is `a` and so the result of calling the `isxdigit ` function is a positive value because `a` is a hexadecimal digit character. But the result of the second character is 0 because the actual value of the character is `?` and it’s not a hexadecimal digit character.

FAQ:

What is ffff to Decimal?

The value ffff in hexadecimal is equal to 65535 in decimal.

Facebook
Twitter
Pinterest
LinkedIn

Top Technologies