Skip to content

Instantly share code, notes, and snippets.

@pinglunliao
Last active November 5, 2019 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinglunliao/93ee49e0cf64cd653dd3 to your computer and use it in GitHub Desktop.
Save pinglunliao/93ee49e0cf64cd653dd3 to your computer and use it in GitHub Desktop.
a414: 位元運算之進位篇. FYI: https://yunlinsong.blogspot.com/2016/02/a414.html
#include <cstdio>
using namespace std;
int main() {
int n;
while( scanf("%d", &n) != EOF ) {
if( n == 0 )
break;
int carryOnCnt = 0;
if( n & 0x00 )
carryOnCnt = 0;
else {
while( n & 0x01 ) {
carryOnCnt++;
n = n >> 1;
}
}
printf("%d\n", carryOnCnt);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment