fork(3) download
  1. #include <stdio.h>
  2. int popcount_gcc(int n) {
  3. return __builtin_popcount(n);
  4. }
  5. int popcount_7bits(int n) {
  6. return (n >> 0 & 1)
  7. + (n >> 1 & 1)
  8. + (n >> 2 & 1)
  9. + (n >> 3 & 1)
  10. + (n >> 4 & 1)
  11. + (n >> 5 & 1)
  12. + (n >> 6 & 1);
  13. }
  14. int main() {
  15. printf("%d %d %d\n", popcount_gcc('a'), popcount_gcc(127), popcount_gcc(255));
  16. printf("%d %d %d\n", popcount_7bits('a'), popcount_7bits(127), popcount_7bits(255));
  17. return 0;
  18. }
  19.  
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
3 7 8
3 7 7