进制转换

#include <bits/stdc++.h>

using namespace std;

int convert2ten(int a,int num)//将a进制转换为十进制
{
int b=0;
int t;
int i=0;
while(num!=0)
{
t=num%10;
num=num/10;
b+=t*pow(a,i);
i++;
}
return b;
}

int convert2other(int a,int num)//将十进制转换为a进制
{
queue<int> mod;
int t;
while(num!=0)
{
t=num%a;
num=num/a;
mod.push(t);
}
int b=0;
int i=0;
while(!mod.empty())
{
t=mod.front();
mod.pop();
b+=t*pow(10,i);
i++;
}
return b;
}

int main()
{
cout<<convert2ten(9,2022);
return 0;
}

posted @   a_true  阅读(3)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)
点击右上角即可分享
微信分享提示