#include<stdio.h>
#include<string.h>
int main() {
char valor[1000];
long long int valor_i;
int position = 0, count = 0;
while (valor_i > 0) {
int bit = valor_i % 2;
valor[position++] = '0' + bit;
count += bit;
valor_i /= 2;
}
valor[position] = '\0';
for (int count = 0; count <= size / 2 - 1; count++) {
char tmp = valor[count];
valor[count] = valor[size - count - 1];
valor[size - count - 1] = tmp;
}
printf("%s - quantidade de '1' => %d\n", valor
, count
); return 0;
}
I2luY2x1ZGU8c3RkaW8uaD4KI2luY2x1ZGU8c3RyaW5nLmg+CgppbnQgbWFpbigpIHsKICAgIGNoYXIgdmFsb3JbMTAwMF07CiAgICBsb25nIGxvbmcgaW50IHZhbG9yX2k7CiAgICBpbnQgcG9zaXRpb24gPSAwLCBjb3VudCA9IDA7CiAgICBzY2FuZigiJWxsZCIsICZ2YWxvcl9pKTsKICAgIHdoaWxlICh2YWxvcl9pID4gMCkgewogICAgICAgIGludCBiaXQgPSB2YWxvcl9pICUgMjsKICAgICAgICB2YWxvcltwb3NpdGlvbisrXSA9ICcwJyArIGJpdDsKICAgICAgICBjb3VudCArPSBiaXQ7CiAgICAgICAgdmFsb3JfaSAvPSAyOwogICAgfQogICAgdmFsb3JbcG9zaXRpb25dID0gJ1wwJzsKICAgIHNpemVfdCBzaXplID0gc3RybGVuKHZhbG9yKTsKICAgIGZvciAoaW50IGNvdW50ID0gMDsgY291bnQgPD0gc2l6ZSAvIDIgLSAxOyBjb3VudCsrKSB7CiAgICAgICAgY2hhciB0bXAgPSB2YWxvcltjb3VudF07CiAgICAgICAgdmFsb3JbY291bnRdID0gdmFsb3Jbc2l6ZSAtIGNvdW50IC0gMV07CiAgICAgICAgdmFsb3Jbc2l6ZSAtIGNvdW50IC0gMV0gPSB0bXA7CiAgICB9CiAgICBwcmludGYoIiVzIC0gcXVhbnRpZGFkZSBkZSAnMScgPT4gJWRcbiIsIHZhbG9yLCBjb3VudCk7CiAgICByZXR1cm4gMDsKfQ==