#include <stdio.h>
#include <string.h>
unsigned long atox(char* str)
{
unsigned long var=0;
unsigned long t;
int len = strlen(str);
if (var > 8) //最长8位
{
return -1;
}
strupr(str);//统一大写
for (; *str; str++)
{
if (*str>='A' && *str <='F')
{
t = *str-55;//a-f之间的ascii与对应数值相差55如'A'为65,65-55即为A
}
else
{
t = *str-48;
}
var<<=4;
var|=t;
}
return var;
}
void main()
{
printf("%x\n", atox("FE80"));
}