附有二进制输出:
#include<iostream>
#include<stack>
using namespace std;
void bitOutput(int);
void oneNum(int);
int main()
{
oneNum(9999);
getchar();
return 0;
}
void oneNum(int a)
{
int count=0;
while(a)
{
count++;
cout<<"a="<<a<<endl;
bitOutput(a);
bitOutput(a-1);
cout<<endl;
a=a&(a-1);
}
cout<<"a="<<a<<endl;
cout<<count;
}
void bitOutput(int intInput)
{
int a=intInput;
stack<int> stack_int;
while(a)
{
stack_int.push(a%2);
a=a/2;
}
while(!stack_int.empty())
{
cout<<stack_int.top();
stack_int.pop();
}
cout<<endl;
}