fork(1) download
  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<stdint.h>
  4.  
  5. int main() {
  6. char binario[64];
  7. memset(binario, '0', 63);
  8. binario[63] = '\0';
  9. int64_t decimal;
  10. scanf("%jd", &decimal);
  11. int position = 62, count = 0;
  12. while (decimal > 0) {
  13. int bit = decimal & 1;
  14. binario[position--] = '0' + bit;
  15. count += bit;
  16. decimal /= 2;
  17. }
  18. printf("%s - quantidade de '1' => %d", &binario[position + 1], count);
  19. }
Success #stdin #stdout 0s 2172KB
stdin
14
stdout
1110 - quantidade de '1' => 3