python 二进制转十进制,python中将十进制转换为二进制

  python 二进制转十进制,python中将十进制转换为二进制

  文章目录一、代码二、运行结果

  一、代码# include iostream # include CST dio # include cstring # include算法# include cmath # include string # include map # include stack # include vector # include set # include io manip # include queue using namespace STD;//打印转换后的二进制void print(int num,int array[],int index){coutnum 的二进制为:;for(int I=index-1;I=0;I-){ cout array[I];}}//转换器int trans verter(int num){ if(num 0)return-1;如果(数量==0)返回0;int a[1024];int index=0;int temp=num for(int I=0;i1024I){索引;if(temp==1){ a[I]=1;打破;} if(temp % 2==0){ a[I]=0;} else { a[I]=1;}温度=临时/2;}print(num,a,index);coutendl}int main(){ //测试用例转换器(-1);转换器(0);转换器(10);转换器(123);横向转换器(789);转换器(123567);返回0;} 二、运行结果10的二进制为:1010123的二进制为:1111011789的二进制为:1100010101123567的二进制为:11110001010101111

郑重声明:本文由网友发布,不代表盛行IT的观点,版权归原作者所有,仅为传播更多信息之目的,如有侵权请联系,我们将第一时间修改或删除,多谢。

留言与评论(共有 条评论)
   
验证码: