posts - 95,  comments - 25,  trackbacks - 0
方法一:
 i=sizeof(int)*8;
 scanf("%d",&a);
int j = a>>i&1;
for(;i>0;i--,printf("%d",a>>i&1));
方法二:
long dnum;
char * cnum;
cnum = new char[100];
printf("please input a decimal number:\n");
scanf("%ld",&dnum);
ltoa(dnum,cnum,2);
printf("the binary number is:%s",cnum);
方法三:
 while(index>0)
  {
    a[i]=index % 2;
 index=index/2;
 i--;
posted on 2005-11-25 11:17 不再专注于.net技术 阅读(28) 评论(0) 编辑 收藏