整形转换为二进制的字符串
#include <iostream>
using namespace std;
void DecToBin(unsigned int dec,char ch[] )
{
int i = 31;
while(i >= 0)
{
int temp = dec;
temp = temp >> i;
ch[32-i-1] = (temp & 1)+'0';
i--;
}
}
int main()
{
char ch1[33];
DecToBin(12,ch1);
ch1[32] = '\0';
cout<<ch1<<endl;
}
输出: