二分查找32位整数的前导0个数 - Try86 - 博客园
int main() { unsigned int n; while (scanf("%u", &n) != EOF) { if (n == 0) printf ("32\n"); else { int s = 1; if ((n >> 16) == 0) {s += 16; n <<= 16;} if ((n >> 24) == 0) {s += 8; n <<= 8;} if ((n >> 28) == 0) {s += 4; n <<= 4;} if ((n >> 30) == 0) {s += 2; n <<= 2;} s -= (n >> 31); printf ("%d\n", s); } } return 0; }Read full article from 二分查找32位整数的前导0个数 - Try86 - 博客园