Skip to content

C 语言学习笔记:十进制转二进制

Published: at 07:47 AMSuggest Changes

进制转换

代码

下面的这个是正确的代码,可以正常的输出打印二进制值

int * test10_jinzhizhuanhuan(int num) {
    int a[100] = {0};
    int i = 0;
    while (num != 0) {
        a[i] = num % 2;
        num = num / 2;
        cout << a[i] << endl;
        i++;
    }
    return a;
}

但是在此之前我犯了一个错误,我用的 char,导致输出的值成了 AAA

char * test10_jinzhizhuanhuan(int num) {
    char a[100] = "";
    int i = 0;
    while (num != 0) {
        a[i] = num % 2;
        num = num / 2;
        cout << a[i] << endl;
        i++;
    }
    return a;
}

Previous Post
跨窗口、Tab 页通信方法总结
Next Post
JS SHA256 加密