C++ isxdigit()

isxdigit() Prototype

int isxdigit(int ch);

The isxdigit() function checks if ch is a hexadecimal numeric character as classified by the current C locale. The available hexadecimal numeric characters are:

  • Digits (0 to 9)
  • Lowercase alphabets from a to f
  • Uppercase alphabets from A to F

The behaviour of isxdigit() is undefined if the value of ch is not representable as unsigned char or is not equal to EOF.

It is defined in <cctype> header file.

isxdigit() Parameters

ch: The character to check.

isxdigit() Return value

The isxdigit() function returns non zero value if ch is a hexadecimal character, otherwise returns zero.

Example: How isxdigit() function works

#include <cctype>
#include <iostream>
#include <cstring>

using namespace std;

int main()
{
    bool flag = 0;
    char str[] = "50Af";

    for (int i=0; i<strlen(str); i++)
    {
        if (!isxdigit(str[i]))
        {
            flag = 1;
            break;
        }
    }

    if (flag)
        cout << str << " is not a valid hexadecimal number";
    else
        cout << str << " is a valid hexadecimal number";
    
    return 0;
}

When you run the program, the output will be:

50Af is a valid hexadecimal number
Did you find this article helpful?

Our premium learning platform, created with over a decade of experience and thousands of feedbacks.

Learn and improve your coding skills like never before.

Try Programiz PRO
  • Interactive Courses
  • Certificates
  • AI Help
  • 2000+ Challenges