Skip to content

Instantly share code, notes, and snippets.

@rabiulcste
Last active April 26, 2016 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rabiulcste/413605f0fbd9205f9243f7e719bf6bee to your computer and use it in GitHub Desktop.
Save rabiulcste/413605f0fbd9205f9243f7e719bf6bee to your computer and use it in GitHub Desktop.
int countSetBits(unsigned int n)
{
unsigned int count = 0;
while(n)
{
count += n & 1; // ভাগশেষ ০ নাকি ১ । যদি ১ হয় তাহলে কাউন্টের মান বেড়ে যাবে ।
n >>= 1; // n কে দুই দিয়ে ভাগ করা হচ্ছে ।
}
return count;
}
int main()
{
int i = 9;
printf("%d", countSetBits(i));
getchar();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment