Skip to main content

C program to count the number of set bits in an unsigned integer

C program to count the number of set bits in an unsigned integer


/*
Program to count no. of bits in an unsigned integer
*/
void main( void )
{
unsigned int a = 15;
int count = 0;

while( a )
{
++count;
a = a & ( a – 1 );
}

clrscr();
printf( “Count is %d\n”, count );
getch();
}

Comments

Popular posts from this blog

CAN INTERVIEW QUESTIONS

Qualifiers and Modifier in C

RTOS Real time operating system interview questions

CAN INTERVIEW QUESTIONS 2

What is UDS protocol

Memory mapping in c

TOP IOT PLATFORMS