Search This Blog
Welcome to 1printf(), your ultimate destination for C, C++, Linux, Data Structures, and Microcontroller programming! ๐ ๐นLearn advanced coding techniques in C& C++ ๐นMaster Linux internals & shell scripting ๐นDeep dive into Data Structures & Algorithms ๐นExplore Embedded Systems & Microcontrollers (8051,UART, RTOS) ๐นGet hands-on coding tutorials, project ideas,and interview preparation tips Whether you're a beginner or an experienced programmer, this channel will help you
Featured
- Get link
- X
- Other Apps
Count Non-Set (0) Bits in a 32-bit Integer in c
๐งฎ Count Non-Set (0) Bits in a 32-bit Integer
#include <stdio.h>
int main()
{
unsigned int num;
int count = 0;
// Read input from user
printf("Enter the number : ");
scanf("%u", &num);
// Loop through all 32 bits
for (int i = 0; i < 32; i++)
{
if ((num & (1 << i)) == 0)
{
count++;
}
}
// Output result
printf("The count of non set bits is %d\n", count);
return 0;
}
๐ Explanation:
๐น The program loops over each bit of a 32-bit unsigned integer using a bitwise AND operation.
๐น If a bit is 0, it increments the `count` of non-set bits.
๐น Works for any unsigned integer in the 32-bit range.
๐งช Sample Output:
Enter the number : 10
The count of non set bits is 30
๐ท️ Keywords:
C program to count 0 bits, count unset bits, bitwise logic, 32-bit integer, technical interview question, C beginner practice
Popular Posts
C++ Program for Hybrid Inheritance (All Types Together)
- Get link
- X
- Other Apps
C++ Program for Function Overloading Example
- Get link
- X
- Other Apps
Comments
Post a Comment