#include <math.h>
int ssCtoi(TCHAR c, int rad)
{
if( (c >= TEXT('a') && c <= TEXT('f')) )
{
if(rad >= 16)
{
return c - TEXT('a') + 10;
}
}else if((c >= TEXT('A') && c <= TEXT('F')))
{
if(rad >= 16)
{
return c - TEXT('A') + 10;
}
}else if(c >= TEXT('8') && c <= TEXT('9'))
{
if(rad == 10 || rad == 16)
{
return c - TEXT('0');
}
}else if(c >= TEXT('0') && c <= TEXT('7'))
{
return c - TEXT('0');
}
return 0;
}
int ssTtoi(LPCTSTR lpTextValue)
{
if(lpTextValue == NULL || _tcslen(lpTextValue) <= 0)
{
return 0;
}
LPCTSTR lpCurValuePointer = lpTextValue;
int rad = 10;
if(_tcslen(lpCurValuePointer) <= 0)
{
return 0;
}
if( lpCurValuePointer[0] == TEXT('0') && (lpCurValuePointer[1] == TEXT('x') || lpCurValuePointer[1] == TEXT('X')) )
{
lpCurValuePointer += 2;
rad = 16;
}else if(lpCurValuePointer[0] == TEXT('0'))
{
lpCurValuePointer++;
rad = 8;
}
LPCTSTR lpValuePointerEnd = lpCurValuePointer;
while(lpValuePointerEnd[0] != TEXT('/0'))
{
if( (lpValuePointerEnd[0] >= TEXT('a') && lpValuePointerEnd[0] <= TEXT('f'))
|| (lpValuePointerEnd[0] >= TEXT('A') && lpValuePointerEnd[0] <= TEXT('F')) )
{
if(rad != 16)
break;
}else if(lpValuePointerEnd[0] >= TEXT('8') && lpValuePointerEnd[0] <= TEXT('9'))
{
if(rad != 10 && rad != 16)
break;
}else if(lpValuePointerEnd[0] >= TEXT('0') && lpValuePointerEnd[0] <= TEXT('7'))
{
}else{
break;
}
lpValuePointerEnd++;
}
if(lpValuePointerEnd <= lpCurValuePointer)
{
return 0;
}
int nRetValue = 0;
int nEx = 0;
while( --lpValuePointerEnd >= lpCurValuePointer )
{
nRetValue += (ssCtoi(*lpValuePointerEnd, rad) * pow((float)rad, nEx++));
}
return nRetValue;
}