进制转换
代码
下面的这个是正确的代码,可以正常的输出打印二进制值
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;
}