Last active
November 5, 2019 08:57
-
-
Save pinglunliao/93ee49e0cf64cd653dd3 to your computer and use it in GitHub Desktop.
a414: 位元運算之進位篇. FYI: https://yunlinsong.blogspot.com/2016/02/a414.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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