#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);
}
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
暂无讨论,说说你的看法吧
幸运之星正在降临...
点击领取今天的签到奖励!
恭喜!您今天获得了{{mission.data.mission.credit}}积分
我的优惠劵
-
¥优惠劵使用时效:无法使用使用时效:
之前
使用时效:永久有效优惠劵ID:×
没有优惠劵可用!