1.在C中,按指定进制格式输出如下:
#include
#include
using namespace std;
int main()
{
printf(“%o\n”,35); // 八进制格式输出:%o
printf(“%d\n”,35); // 十进制格式输出:%d
printf(“%x”,35); // 十六进格式制输出:%x或者%X
return 0;
}
// 输出结果:
43
35
23
2.在C++中,按指定进制格式输出如下:
#include
using namespace std;
int main()
{
cout<<oct<<35<<endl; // 八进制输出格式 oct
cout<<dec<<35<<endl; // 十进制输出格式 dec
cout<<hex<<35<<endl; // 十六进制输出格式 hex
return 0;
}
// 输出:
43
35
23
3.任意2-36进制数转化为10进制数
- 自己写一个函数
建议自己可以去敲一敲,加深记忆
#include
using namespace std;
int turn (string a,int t)
{
int sum=0;
for(int i=a.size()-1;i>=0;