isxdigit Function

Test for a hexadecimal digit.




int isxdigit (int c);


The character to test.

Return Value

Returns a non-zero integer value if the character, c, is a hexadecimal digit; otherwise, returns zero.


A character is considered to be a hexadecimal digit character if it is in the range of '0'-'9', 'A'-'F', or 'a'-'f'.

Note: The list does not include the x character, which is used when writing a hexadecimal value, such as 0x7FFE. This function looks purely to see if the character is a hexadecimal digit.


See the notes at the beginning of this chapter or section for information on using printf() or scanf() (and other functions reading and writing the stdin or stdout streams) in the example code.

#include <ctype.h>
#include <stdio.h>

int main(void)
  int ch;

  ch = 'B';
  if (isxdigit(ch))
    printf("B is a hexadecimal digit\n");
    printf("B is NOT a hexadecimal digit\n");

  ch = 't';
  if (isxdigit(ch))
    printf("t is a hexadecimal digit\n");
    printf("t is NOT a hexadecimal digit\n");

Example Output

B is a hexadecimal digit
t is NOT a hexadecimal digit