• <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進(jìn)制字符串轉(zhuǎn)換成10進(jìn)制數(shù)

            #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
            <<"十六進(jìn)制字符串不對"<<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進(jìn)制字符串轉(zhuǎn)換成10進(jìn)制數(shù) 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;
            }  回復(fù)  更多評論   

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

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章分類

            文章檔案

            收藏夾

            搜索

            最新評論

            久久国产精品成人影院| 久久天天躁夜夜躁狠狠| 国产午夜精品理论片久久 | 久久精品aⅴ无码中文字字幕重口| 国内精品久久久久久99蜜桃 | a高清免费毛片久久| 久久人人爽人爽人人爽av| 亚洲精品午夜国产VA久久成人| 久久久久国产精品| 五月丁香综合激情六月久久| 久久天天躁狠狠躁夜夜av浪潮| 久久人人爽人人爽人人片av高请| 国产免费久久精品99久久| 青草国产精品久久久久久| 欧美日韩精品久久久久 | 久久亚洲精品无码aⅴ大香| 久久九九亚洲精品| 久久综合88熟人妻| 2021最新久久久视精品爱| 国产精品亚洲综合专区片高清久久久 | 囯产精品久久久久久久久蜜桃| 国产精自产拍久久久久久蜜| 97久久久精品综合88久久| 久久午夜伦鲁片免费无码| 久久午夜福利无码1000合集| 久久久精品日本一区二区三区| 亚洲乱亚洲乱淫久久| 久久综合九色综合精品| 久久精品国产91久久综合麻豆自制 | 久久影院午夜理论片无码| 91精品国产综合久久久久久| 国产精品免费福利久久| 亚洲中文字幕无码久久2017| 久久久久亚洲AV片无码下载蜜桃| 亚洲精品高清一二区久久| 亚洲国产天堂久久久久久| 99久久综合国产精品免费| 欧美激情一区二区久久久| 精品国产乱码久久久久软件| 久久精品国产2020| 久久99精品国产自在现线小黄鸭|