C programming isxdigit ctype.h


In C programming the <ctype.h> isxdigit function test if the character is a hexadecimal-digit character.In “C” locale-the default locale- only the character between ‘0’ to ‘9’ and ‘A’ to ‘F’ and ‘a’ to ‘f’ are considered as hexadecimal-digit character.The declaration of the function is given below.

int isxdigit(int c);

Parameters:
c -The character to be tested for hexadecimal type.

Return type
int -Return non-zero value if the character is hexadecimal character.

Note in different locale the characters which are validated as hexadecimal-digit will depend on that locale.The code example given below is meant for “C” locale.

Code example

printf(“%d” , isxdigit(‘A’) );

printf(“\n%d” , isxdigit( ‘e’ ) );

printf(“\n%d” , isxdigit( 52 ) );

printf(“\n%d” , isxdigit(‘\x39’) );

printf(“\n%d” , isxdigit(‘x2’) );

printf(“\n%d” , isxdigit(0) );

printf(“\n%d” , isxdigit(‘m’) );

Output,

128
128
128
128
0
0
0

In the third line,the argument pass is 52 this value represent the character ‘4’ in ASCII table so the function return true.

In the fourth line the argument passed is ‘\x39’,converting this to integer we get 57, and 57 represent the character ‘9’ in ASCII table,thus the function return true.


Related links

->C isdigit

->C isupper

->C isgraph

->C isalpha