十进制转二进制(最简代码)

#include"iostream"
#include"stdio.h"
using namespace std;

string dui[8]={"000","001","010","011","100","101","110","111"};

int main()
{   
    char ai[100]; int a=125; string jj;
    sprintf(ai,"%o",a);
    for(int i=0;ai[i];i++) jj+=dui[ai[i]-'0'];
    cout<<jj;
    return 0;
}

思路:先将十进制转化为八进制并存储在字符串中,然后八进制以一位对三位转化为二进制

    原文作者:进制转换
    原文地址: https://blog.csdn.net/sb_ihateyou/article/details/70855458
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞