C Function Isxdigit
# C Library Function - isxdigit()
[ C Standard Library - ](#)
## Description
The C library function **int isxdigit(int c)** checks whether the passed character is a hexadecimal digit.
The parameter **c** for **int isxdigit(int c)** is a single character.
Hexadecimal numbers are generally represented using digits 0 to 9 and letters A to F (or a~f), where A~F represent 10~15: **0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F**.
## Declaration
Below is the declaration for the isxdigit() function.
int isxdigit(int c);
## Parameters
* **c** -- This is the character to be checked.
## Return Value
If c is a hexadecimal digit, the function returns a non-zero integer value, otherwise it returns 0.
## Example
The following example demonstrates the usage of the isxdigit() function.
## Example
#include#includeint main(){char c = '5'; int result; // Pass in a character result = isxdigit(c); // result returns non-0 printf("%c passed to isxdigit() function result: %d", c, isxdigit(c)); printf("n"); // Newline c = 'M'; // Non-hexadecimal digit as parameter result = isxdigit(c); // result is 0 printf("%c passed to isxdigit() function result: %d", c, isxdigit(c)); return 0; }
Let us compile and run the above program, this will produce the following result:
5 passed to isxdigit() function result: 1 M passed to isxdigit() function result: 0
Find hexadecimal digit characters in a string:
## Example
#include#includeint main(){char str[]="123c@#run[oobe?"; int i; for(i=0;str!='';i++){if(isxdigit(str)){printf("%c is a hexadecimal digitn",str); }}}
Let us compile and run the above program, this will produce the following result:
1 is a hexadecimal digit2 is a hexadecimal digit3 is a hexadecimal digit c is a hexadecimal digit b is a hexadecimal digit e is a hexadecimal digit
[ C Standard Library - ](#)
YouTip