#include <stdio.h>

int main(){
    int bin = 0b10101010;
    int hex = 0xA10;//1010 0001 0000

    //A hexadecimal digit represents values from 0 to 15, or 0000 to 1111 in binary.
    //In other words, one hexadecimal digit maps to 4 binary digits (bits).

    int c = 0;

    while(bin!=0){
        if(bin & 0b1 == 1){
            c++;
        }
        bin = bin >> 1;
    }

    int n = 0;

    while(hex!=0){
        if(hex & 0b1 == 1){
            n++;
        }
        hex = hex >> 4;
    }

    printf("%d\n",c);
    printf("%d\n",n);
}

Embed on website

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