English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The isxdigit() function checks if a character is a hexadecimal digit character (0-9, af, AF).
The function prototype of isxdigit() is:
int isxdigit(int arg);
It is<ctype.h>Defined in the header file.
The isxdigit() function takes a single character as a parameter.
Note:In C programming, characters are internally treated as int values.
If the argument passed to isxdigit() is
Hexadecimal character, isxdigit() returns a non-zero integer.
Non-hexadecimal character, isxdigit() returns 0.
#include <ctype.h> #include <stdio.h> int main() { char c = '5'; int result; //Passing a hexadecimal character result = isxdigit(c); // Result is not zero printf("When %c is passed to isxdigit(): %d", c, isxdigit(c)); c = 'M'; //Non-hexadecimal character passed result = isxdigit(c); // result is 0 printf("\nWhen %c is passed to isxdigit(): %d", c, isxdigit(c)); return 0; }
Output Result
When 5 Result when passed to isxdigit(): 128 Result when M is passed to isxdigit(): 0
#include <ctype.h> #include <stdio.h> int main() { char c = '5'; printf("Enter a character: "); c = getchar(); if (isxdigit(c) != 0) {}} printf("%c is a hexadecimal character.", c); } else { printf("%c is not a hexadecimal character.", c); } return 0; }
Output Result
Enter a character: f f is a hexadecimal character.