hex2int

 

/*hex string*/

unsigned int HEX2int(char *pcBCD)

{

char acBCD[8] = {0};

unsigned int nReval = 0;

int nPower = 1;

int nStrlen = strlen(pcBCD);

memcpy(acBCD, pcBCD, nStrlen);

while(nStrlen--)

{

/*

if(acBCD[nStrlen] >= 'A' && acBCD[nStrlen] <= 'F')

{

nReval += (acBCD[nStrlen] - 55)*nPower;

}

else if(acBCD[nStrlen] >= 'a' && acBCD[nStrlen] <= 'f')

{

nReval += (acBCD[nStrlen] - 87)*nPower;

}

*/

if(isdigit(acBCD[nStrlen]) == 0)

{

acBCD[nStrlen] = acBCD[nStrlen]&0x4f;

nReval += (acBCD[nStrlen] - 55)*nPower;

}

else

{

nReval += (acBCD[nStrlen] - '0')*nPower;

}

nPower *= 16; 

}

return nReval;

}

 

 

你可能感兴趣的:(String,hex)