函式
<cctype>

isxdigit

int isxdigit ( int c );
檢查字元是否為十六進位制數字
檢查c是否為十六進位制數字字元。

十六進位制數字包括0 1 2 3 4 5 6 7 8 9 a b c d e f A B C D E F

有關不同ctype函式為標準 ANSII 字元集中的每個字元返回的值,請參閱 <cctype> 標頭檔案的參考。

在C++中,此函式的本地化特定模板版本(isxdigit)存在於標頭<locale>中。

引數

c
要檢查的字元,轉型為int型別,或EOF.

返回值

如果 c 確實是空白字元,則返回一個非零值(即true) 如果c確實是十六進位制數字。零(即false)。

示例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* isxdigit example */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
int main ()
{
  char str[]="ffff";
  long int number;
  if (isxdigit(str[0]))
  {
    number = strtol (str,NULL,16);
    printf ("The hexadecimal number %lx is %ld.\n",number,number);
  }
  return 0;
}

isxdigit用於檢查中的第一個字元str是否為有效的十六進位制數字,因此可以被strtol成功轉換為整型值。輸出
The hexadecimal number ffff is 65535.


另見