C Programming Code Examples C > Bitwise Operators Code Examples Program to count leading zeros in a binary number using while loop Program to count leading zeros in a binary number using while loop Write a C program to input any number from user and find total number of leading zeros of the given number. How to find total leading zeros of a given number (in binary representation) using bitwise operator in C programming. Logic to count total leading zeros of a given number using C programming. #include <stdio.h> #include <limits.h> // Used for INT_MAX int main() { int j, count; /* Input number from user */ printf("Enter any number: "); scanf("%d", &j); count = 0; while(!(j & (~INT_MAX))) { count++; j <<= 1; } printf("Total number of leading zeros = %d", count); return 0; }