Program to count Set Bits in an integer value

Manojjupally
Posted by Manojjupally under C# category on | Points: 40 | Views : 919
Count Set Bits


public static void Count()
{
int n = 7;
int count = 0;
while (n > 0)
{
count += n & 1;
n = n >> 1;
}
Console.WriteLine(count);
}

Comments or Responses

Login to post response