Hi askis!

May be this example below can help you:

Code:

/** tallybit.c read in a integer value, as a 4-Byte(32Bit) integer
* and counts the digits where are set and not set.
* If you read in a negativ integer it shows how does it looks
* in binary(Two's complement)
* more information at
* https://en.wikipedia.org/wiki/Signed_number_representations
*
* written by Josef Franz Wismeth, in upper palatinate, bavaria
*
* last changes at 2018 December, 26th */
#include <stdio.h>
#include <stdlib.h>
/** counts the number of bits of argument 1, argument_2 = number of bits are set, argument_2 number of bits are not set*/
void tallybin(int intnumber, unsigned int (*bits_set), unsigned int (*bits_not_set))
{
unsigned int i, grot = 0, result, bits_are_on = 0, bits_are_off = 0, bitsize = 0;
bitsize = ((sizeof(int)) * 8);
grot = 1 << (bitsize - 1);
/// can set the line to a comment
printf("size of argument 1 in bit: %d\n", bitsize);
for (i = 0; i <= (bitsize - 1); i++)
{
result = (unsigned int)intnumber & grot;
/// shows the bits, can set this two lines to a comment
if (result) printf("1");
else printf("0");
grot >>= 1;
if (result) bits_are_on++;
else bits_are_off++;
}
(*bits_set) = bits_are_on;
(*bits_not_set) = bits_are_off;
}
int main()
{
int number = 0;
unsigned int bits_on = 0, bits_off = 0;
printf("Counting the bits!\n");
printf("Please enter a integer value: ");
scanf("%d", & number);
printf("\nThe value was: %d\n", number);
tallybin(number, &bits_on, &bits_off);
printf("\nNumber of bits are set: %u\n", bits_on);
printf("Number of bits not set: %u\n", bits_off);
return 0;
}

Hey Mister Tallyman telly me banana...........