#include <stdio.h>
#include <string.h>
typedef unsigned long DWORD;
// 函数功能:16进制字符串转化为数字
// 函数返回:0不是16进制数,1是十六进制数
bool HexstrToHex(char *str, DWORD &dwVal)
{
int nLen;
int i;
int pow;
DWORD s;
char ch;
char *p;
nLen = strlen(str);
p = str + nLen;
if (nLen > 8 || nLen == 0)
return false;
s = 0;
pow = 1;
for(i = nLen; i > 0; i --)
{
ch = *(--p);
if ((ch >= 'a') && (ch <= 'f'))
ch = ch - 'a' + 10;
else if ((ch >= 'A') && (ch <= 'F'))
ch = ch - 'A' + 10;
else if ((ch >= '0') && (ch <= '9'))
ch = ch - '0';
else
return false;
s += ch * pow;
pow *= 16;
}
dwVal = s;
return 1;
}
void main()
{
char str[] = "a0";
DWORD dwVal;
if (!HexstrToHex(str, dwVal))
printf("failed./n");
else
printf("%x/n", dwVal);
}