CSDN博客

img amber1973

十六进制字符串转int64

发表于2002/6/28 16:18:00  636人阅读

#include <math.h>
__int64 Str2Int64(char* str)
{
   if(strstr(str,"0x") || strstr(str,"0X"))
   {
      str += 2;
      __int64 tmp = 0;
      int len = strlen(str);
      for(int i = 0;i < len ;i++)
      {
         int nDecNum;
         switch(str[i])
         {
        case 'a':
        case 'A':
           nDecNum = 10;
           break;
        case 'b':
        case 'B':
           nDecNum = 11;
           break;
         case 'c':
         case 'C':
            nDecNum = 12;
            break;
        case 'd':
        case 'D':
            nDecNum = 13;
            break;
        case 'e':
        case 'E':
            nDecNum = 14;
            break;
        case 'f':
        case 'F':
            nDecNum = 15;
            break;
        case '0':
        case '1':
        case '2':
        case '3':
        case '4':
        case '5':
        case '6':
        case '7':
        case '8':
        case '9':
            nDecNum = str[i] - '0';
            break;
        default:
            return 0;

        }
        tmp += nDecNum*pow(16,len-i -1);
     }
     return tmp;
   }
   else
   {
      return _atoi64(str);
   }
}

0 0

相关博文

我的热门文章

img
取 消
img