十六进制转换等值的整型值:
#define YES 1
#define NO 0
int htos(int s[])
{
int hexdigit,n,i,inhex;
i = 0;
if(s[i] == 0){
i ++;
if(s[i] == 'x' || s[i] == 'X'){
i ++;
}
}
n = 0;
inhex = YES;
for(;inhex == YES;i ++){
if(s[i] => '0' && s[i] <= 9){
hexdigit = s[i] - '0';
}else if(s[i] >= 'a' && s[i] <= 'f'){
hexdigit = s[i] - 'a' + 10;
}else if(s[i] >= 'A' && s[i] <= 'F'){
hexdigit = s[i] - 'A' +10;
}else{
inhex = NO;
}
if(inhex == YES){
n = n * 16 + hexdigit;
}
}
return n;
}
阅读(1096) | 评论(0) | 转发(0) |