/* Include lib */
#include <stdio.h>
#include <assert.h>

/* Define */

/* API get number of bit 1 in a number 32 bits */
int get_no_bit1(unsigned int num)
{
  int cnt = 0;

  while (num) {
    cnt += (num & 0x1);
    num >>= 1;
  }

  return cnt;
}

/* Main func interract with user */
int main(void)
{
  int sel;
  unsigned int num;

  while (1) {
    printf("\n\nSelection:\n");
    printf("0 : Input number\n");
    printf("1 : Exit\n");
    printf("Select: ");
    scanf("%d", &sel);

    switch (sel) {
    case 0:
      printf("Input number 32b: ");
      scanf("%x", &num);
      printf("=> number of bit 1: %d", get_no_bit1(num));
      break;
    case 1: 
      return 0;
    default:
      printf("Option not available\n");
      break;
    }
  }

  return -1;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: