整形转换为二进制的字符串

#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;
}

输出:

posted @ 2012-08-22 22:07  SA高处不胜寒  阅读(1810)  评论(0编辑  收藏  举报