#include "stdafx.h"
#include "stdio.h"
#include <stdlib.h>
#include <process.h>


int main(int argc, char* argv[])
{
 int countx = 0,
  x=9991;
 char szBinary[64]={0};
 printf("please input an int data\n",countx);
 scanf("%d",&x);

 itoa(x,szBinary,2);
 printf("x=%d\t%s\n",x,szBinary);
 while(x)
 {
  countx ++;
  x = x&(x-1);
  itoa(x,szBinary,2);
  printf("x=%d\t%s\n",x,szBinary);
 }
 printf("countx=%d\n",countx);
 system("pause");
// printf("press any key to quit\n",countx);
 return 0;
}

算法固然好,但是不很直觀哦
其實我覺得只要轉化成字符串之后,直接找里面"1"字符就可以了,同樣的擴展性更好,可以轉化成隨意進制,找隨意數字的個數 .