1: bitcnt(var) 2: int var; 3: 4: /* 5: ** Count the number of 1's in the integer var. As long 6: ** as left shift is zero fill this routine is machine 7: ** independent. 8: */ 9: 10: { 11: register int i, j, ret; 12: 13: j = var; 14: 15: for (ret = 0, i = 1; i; i <<= 1) 16: if (i & j) 17: ret++; 18: 19: return (ret); 20: }