• <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 閱讀(754) 評論(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ù)  更多評論   

            <2025年5月>
            27282930123
            45678910
            11121314151617
            18192021222324
            25262728293031
            1234567

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿

            文章分類

            文章檔案

            收藏夾

            搜索

            最新評論

            久久e热在这里只有国产中文精品99 | 91精品国产91久久久久久| 亚洲人成无码www久久久| 亚洲国产二区三区久久| 久久精品麻豆日日躁夜夜躁| 久久亚洲AV永久无码精品| 国产日韩久久久精品影院首页| 久久国产高清字幕中文| 国产V综合V亚洲欧美久久| 国产Av激情久久无码天堂| 99久久99久久久精品齐齐| 粉嫩小泬无遮挡久久久久久| www久久久天天com| 久久噜噜电影你懂的| 国产成人精品久久亚洲高清不卡 | 精品综合久久久久久97超人| 韩国无遮挡三级久久| 国产成人精品久久一区二区三区av | 久久久久亚洲AV成人片| 久久精品国产99久久久| 日本道色综合久久影院| 久久国产精品免费一区| 日本精品久久久久影院日本| 一级做a爰片久久毛片毛片| 亚洲狠狠婷婷综合久久蜜芽| 狠狠狠色丁香婷婷综合久久五月 | 九九精品99久久久香蕉| 久久九九全国免费| 亚洲七七久久精品中文国产 | 亚洲午夜福利精品久久| 色综合久久无码中文字幕| 亚洲狠狠久久综合一区77777| 国产成人久久精品麻豆一区| 国产精品99久久久久久宅男小说| 影音先锋女人AV鲁色资源网久久| 国产精品久久久久jk制服| 亚洲国产精品无码久久98| 久久婷婷激情综合色综合俺也去 | 久久久久久久久久久久久久| 亚洲Av无码国产情品久久| 无码人妻久久一区二区三区免费 |