Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Binary to Decimal Bit Counter

#include <stdio.h>

int binaryCount(unsigned int n) {
       int onesCount;
        while (n != 0) {
            if(n%2 == 1){
                onesCount++;
                n=n/2;
            }
            else {
                n=n/2;
            }
        }
    return onesCount;    
        
    }

int main()
{
    int x = 4294967295u;
    int ones = 0;
    ones = binaryCount(x);
    printf("%d", ones);
    return 0;
}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.