fork download
  1. #include <stdio.h>
  2.  
  3. char split_lookup[] = {
  4. 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4
  5. };
  6.  
  7. int bit_count(unsigned char n) {
  8. return split_lookup[n&0xF] + split_lookup[n>>4];
  9. }
  10.  
  11. int main(void) {
  12.  
  13. for (int i = 0 ; i != 256 ; i++) {
  14. int count = 0;
  15. for (int p = 0 ; p != 8 ; p++) {
  16. if (i & (1 << p)) {
  17. count++;
  18. }
  19. }
  20. if (bit_count(i) != count) {
  21. printf("Bad: %d\n", i);
  22. }
  23. }
  24.  
  25.  
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0s 2004KB
stdin
Standard input is empty
stdout
Standard output is empty