版权声明:Wechat:chi0707007 微博:奇葩奇葩铁树开花 https://blog.csdn.net/weixin_44986776/article/details/89812454
6.1 Introduction NULL
6.2 定义一个函数
6.3 函数调用
6.4 void 函数
6.5
6.14 例子–十六进制转化为十进制
#include <iostream>
#include <string>
#include <cctype>
using namespace std;
int hex2Dec(const string& hex);
int hexCharToDecimal(char ch);
char DecimalToHex(int num);
int main(){
string string;
cin>>string;
cout<<hex2Dec(string)<<endl;
}
int hex2Dec(const string&hex){
int DecValue = 0;
for(unsigned i=0;i<hex.size();i++)
DecValue = DecValue * 16 + hexCharToDecimal(hex[i]);
return DecValue;
}
int hexCharToDecimal(char ch)//十六进制转化为10h进制
{
ch = toupper(ch);
if(ch>='A'&&ch<='F')
return 10+ch - 'A';
else
return ch-'0';
}
char DecimalToHex(int num) //十进制转化为十六进制
{
return static_cast<char>('A'+(num-10));
}