/* Orion Lawlor's Simple C++ Examples, olawlor@acm.org
  Build a table that counts the number of set bits in the input byte.
*/
#include <stdio.h>
typedef int (*table_fn)(int in); 
void printTable(int lo,int hi,table_fn fn) {
	for (int i=lo;i<hi;i++) {
		//if ((i%16)==0) printf("\n/* %3d */ ",i);
		printf("%d,",fn(i));
	}
}  
int countBits(int i) {
	int t,s=0; 
	for (int t=1;t!=0;t<<=1) 
		if ((i&t)!=0) 
			s++; 
	return s;
}
int main() { printTable(0,256,countBits); return 0; }
/*<@>
<@> ******** Program output: ********
<@> 
<@> /*   0 */ 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,
<@> /*  16 */ 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
<@> /*  32 */ 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
<@> /*  48 */ 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
<@> /*  64 */ 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
<@> /*  80 */ 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
<@> /*  96 */ 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
<@> /* 112 */ 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
<@> /* 128 */ 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
<@> /* 144 */ 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
<@> /* 160 */ 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
<@> /* 176 */ 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
<@> /* 192 */ 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
<@> /* 208 */ 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
<@> /* 224 */ 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
<@> /* 240 */ 4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8,
<@> */
