A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 尾尾 中级黑马   /  2015-9-29 22:07  /  541 人查看  /  0 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. #include <stdio.h>
  2. void shuChuErJinZhiShu(int a)
  3. {
  4.     //解决没有符号位
  5.     if(a<0) {
  6.         printf("1");
  7.     } else {
  8.         printf("0");
  9.     }
  10. //    int b=8;
  11. //    int c=b>>2;
  12. //    printf("*******b:%d,c:%d\n",b,c);
  13.     int count = (sizeof(int)*8)-2;//第一次平移的位数
  14.     int temp = 0;//每一位的结果
  15.     while (count>=0) {
  16. //        temp =  a>>count&1;//获取每一位的结果
  17.         a>>2;
  18.         printf("a第在count=%d时为%d\n",count,a);
  19.         printf("%d",temp);//打印每一位的结果
  20.         if(0==count%4) printf(" ");//每隔4位打印一个空格
  21.         count--;//下一次平移的位数比当前少1
  22.     }
  23.     printf("\n");
  24. }

  25. //main函数
  26. int main()
  27. {
  28.     shuChuErJinZhiShu(8);
  29.     return 0;
  30. }
复制代码

0 个回复

您需要登录后才可以回帖 登录 | 加入黑马