利用位运算判断最后一位是不是1,如果不是的话就把A向右移一位,并把计数器向左移一位(即乘二)
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int A;
scanf("%d",&A);
while(A){
int temp=1;;
while(!(A&1)){
A>>=1;
temp<<=1;
}
printf("%d\n",temp);
scanf("%d",&A);
}
return 0;
}