#include
#include
void htoi(char *);
int main()
{
char *hex="0xFFFF";
htoi(hex);
return 0;
}
void htoi(char *hexstr)
{
char c;
int val=0,i;
int len=strlen(hexstr);
for(i=0;i
c=*(hexstr+2); //pointer will points to F in case of 0xFFFF
if(c>='a' && c<='f')
{
val=val*16+(c-'a'+10);
}
else if(c>='A' && c<='F')
{
val=val*16+(c-'A'+10);
}
else
{
if(c>='0' && c<='9')
{
val=val*16+(c-'0');
}
}
printf("Val: %d \t ",val);
hexstr++;
}
printf("\n Val: %d ",val);
}
No comments :
Post a Comment