• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            將16進制字符串轉換成10進制數

            #include <iostream>
            using namespace std;
            #include 
            <cassert>
            #include 
            <string>
            //
            int hexstr2dec(const char* str){
                
            int result=0;
                
            int decnum=0;
                
            int len=strlen(str);
                
            for(int i=0;i<len;i++){
                    
            if(str[i]<='9'&&str[i]>='0')
                        decnum
            =str[i]-'0';
                    
            else if(str[i]<='f'&&str[i]>='a')
                        decnum
            =str[i]-'a'+10;
                    
            else if(str[i]<='F'&&str[i]>='A')
                        decnum
            =str[i]-'A'+10;
                    
            else{
                        cout
            <<"十六進制字符串不對"<<endl;
                        
            return -1;
                    }

                    decnum
            <<=(len-i-1)<<2;
                    result
            +=decnum;
                }

                
            return result;
            }


            int main()
            {
                
            string str;
                cin
            >>str;
                cout
            <<hexstr2dec(str.c_str())<<endl;//str.c_str()為const char*
                system("pause");
                
            return 0;
            }

            posted on 2011-06-10 12:22 Hsssssss 閱讀(775) 評論(1)  編輯 收藏 引用 所屬分類: C++代碼

            評論

            # re: 將16進制字符串轉換成10進制數 2011-07-13 10:26 xuorc1986

            int hexstr2dec(const char* str)
            {
            int result = 0;
            int decnum = 0;
            int i = 0;
            int length = strlen(str);

            do
            {
            if(str[i]<='9'&&str[i]>='0')
            decnum=str[i]-'0';
            else if(str[i]<='f'&&str[i]>='a')
            decnum=str[i]-'a'+10;
            else if(str[i]<='F'&&str[i]>='A')
            decnum=str[i]-'A'+10;
            else{
            return result;
            }
            result <<= (i << 2);
            result += decnum;

            } while (i++ < length);

            return result;
            }  回復  更多評論   

            <2011年7月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            導航

            統計

            常用鏈接

            留言簿

            文章分類

            文章檔案

            收藏夾

            搜索

            最新評論

            久久这里有精品| 亚洲Av无码国产情品久久| 亚洲伊人久久精品影院| 久久综合精品国产二区无码| 久久久久久久亚洲Av无码| 狠狠色婷婷综合天天久久丁香 | 2021精品国产综合久久| 精品久久久久中文字幕一区| 亚洲伊人久久精品影院| 国产精品熟女福利久久AV| 伊人久久大香线蕉av一区| 久久AⅤ人妻少妇嫩草影院| 欧美一区二区三区久久综| 久久综合久久性久99毛片| 精品一区二区久久| 狠狠色狠狠色综合久久| 日韩久久久久中文字幕人妻| 91亚洲国产成人久久精品| 漂亮人妻被黑人久久精品| 久久婷婷午色综合夜啪| 欧美性大战久久久久久| 99精品久久久久久久婷婷| 国产精品久久久久9999| 久久久免费精品re6| 奇米综合四色77777久久| 久久人妻AV中文字幕| 亚洲国产精品综合久久一线| 久久精品国产亚洲AV不卡| 国产精品熟女福利久久AV| 久久99免费视频| 99久久777色| 久久夜色精品国产亚洲| 国产国产成人精品久久| 99久久99久久| 久久国产影院| 亚洲va久久久久| 久久人做人爽一区二区三区| 久久狠狠爱亚洲综合影院| 精品多毛少妇人妻AV免费久久| 国产精品成人无码久久久久久 | 久久精品亚洲福利|