C++ Standard Library C++ STL Library

C++ <cctype> - isxdigit() Function



The C++ <cctype> isxdigit() function is used to check if the given character is a hexadecimal digit or not. Hexadecimal digits are one of the following character: 0123456789abcdefABCDEF.

Syntax

int isxdigit ( int ch );               

Parameters

ch Specify the character to be checked, casted to an int, or EOF.

Return Value

Returns non-zero value (i.e, true) if ch is a hexadecimal digit, else returns zero (i.e, false).

Example:

The example below shows the usage of isxdigit() function.

#include <iostream>
#include <cctype>
using namespace std;
 
int main (){
  char str[] = "ff123YZ";

  //counting the numbers of 
  //hexadecimal digits in str
  int i = 0, count = 0;
  while(str[i]) {
    if(isxdigit(str[i]))
      count++;
    i++;
  }

  //displaying the output
  cout<<str<<" contains "<<count<<
       " hexadecimal digits.";  
  return 0;
}

The output of the above code will be:

ff123YZ contains 5 hexadecimal digits.

❮ C++ <cctype> Library