码迷,mamicode.com
首页 > 其他好文 > 详细

16进制转10

时间:2020-01-21 13:32:40      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:stream   ret   --   code   namespace   mes   ring   style   string   

注意高位低位次序即可

#include<iostream>
#include<string>
#include<cmath>
using namespace std;
long long fun(char c,int n){
    long long  temp=0;
    int i;
    switch(c)
    {
        case ‘F‘: temp=15; break;
        case ‘E‘: temp=14; break;
        case ‘D‘: temp=13;break;
        case ‘C‘: temp=12;break;
        case ‘B‘: temp=11;break;
        case ‘A‘: temp =10;break;
        case ‘9‘:temp =9;break;
        case ‘8‘:temp =8;break;
        case ‘7‘:temp =7;break;
        case ‘6‘:temp =6;break;
        case ‘5‘:temp =5;break;
        case ‘4‘:temp =4;break;
        case ‘3‘:temp =3;break;
        case ‘2‘:temp =2;break;
        case ‘1‘:temp =1;break;
        case ‘0‘:temp =0;break;
    }
    for(i=0;i<n;i++){
        temp=temp*16;    
    }
    return temp;
}
int main(){
    string a;
    int n,i,j;
    cin>>a;
    long long num=0;
    for(i=a.length()-1,j=0;i>=0;i--,j++){
        num=num+fun(a[i],j);
    }
    cout<<num<<endl;
}

16进制转10

标签:stream   ret   --   code   namespace   mes   ring   style   string   

原文地址:https://www.cnblogs.com/joker99/p/12221368.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!