• <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 閱讀(762) 評論(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;
            }  回復  更多評論   

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導航

            統計

            常用鏈接

            留言簿

            文章分類

            文章檔案

            收藏夾

            搜索

            最新評論

            国产精品久久久久久吹潮| 欧美久久久久久| 久久久精品国产亚洲成人满18免费网站 | 久久99热精品| 精品无码久久久久久久久久| 理论片午午伦夜理片久久 | 欧美日韩成人精品久久久免费看| 久久亚洲国产精品123区| 亚洲成色www久久网站夜月| 久久这里只有精品久久| 精品熟女少妇AV免费久久| 久久91精品国产91久久小草| 亚洲国产高清精品线久久| 久久精品国产精品亚洲精品| 思思久久99热只有频精品66| 91久久精品电影| 无码久久精品国产亚洲Av影片| 国产AⅤ精品一区二区三区久久| 亚洲va国产va天堂va久久| 久久久久亚洲AV无码专区桃色 | 久久久久久九九99精品| 日韩一区二区三区视频久久| 欧美日韩中文字幕久久伊人| 久久天天躁狠狠躁夜夜躁2O2O| 亚洲精品NV久久久久久久久久| 99久久精品国产一区二区蜜芽| 久久A级毛片免费观看| 亚洲AV乱码久久精品蜜桃| 久久久亚洲AV波多野结衣| 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 久久久久亚洲AV无码专区桃色| 91久久精一区二区三区大全| 久久综合狠狠综合久久综合88| 亚洲人成精品久久久久 | 久久国产乱子伦精品免费强| 97久久天天综合色天天综合色hd | 久久精品国产精品亜洲毛片| 91久久精品视频| 久久九九久精品国产| 久久伊人五月天论坛| 欧美日韩精品久久久久|