文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>a program a day 12

a program a day 12

时间:2010-10-08  来源:生无涯

/**
计算一个字节中1和0的位数
**/
#include<stdio.h>
int bitNumber(unsigned char c,int & count1,int & count0)
{
 unsigned char tmp = 0x1;
 for(int i = 0;i < 8;i++)
 {
  if((c & tmp) != 0)        
  {
   count1 ++;
  }
  else count0 ++;
  tmp = tmp << 1;           //若定义tmp = 0x1 << 7,此处可改为tmp >> 1;
 }
 return 1;
}
int main()
{
 int count1 = 0,count0 = 0;
 unsigned char c;
 printf("please input a character:\n");
 scanf("%c",&c);
 bitNumber(c,count1,count0);
 printf("the number of bit '1' in this character is : %d\n",count1);
 printf("the number of bit '0' in this character is : %d\n",count0);
 return 1;
}

相关阅读 更多 +
排行榜 更多 +
枪战大乱斗2

枪战大乱斗2

飞行射击 下载
猎鸭挑战安卓版

猎鸭挑战安卓版

飞行射击 下载
空军

空军

飞行射击 下载