Write a program to count set bits in a byte first with naive method and then unroll the loop
Sigiloso
1) n&=n-1 2)write two macro.. each for Low Nibble and High Nibble example: #define count_bits_low_nibble (n) (n>>3)&1+(n>>2)&1+(n>>1)&1+(n&1) same as for high nibble with changes.. (n>>7)&1+(n>>6)&1+(n>>5)&1+(n>>4)&1 need to take care of last high bit.. there is another method : v = v - ((v >> 1) & 0x55555555) v = (v & 0x33333333) + ((v >> 2) & 0x33333333) c = ((v + (v >> 4) & 0xF0F0F0F) * 0x1010101) >> 24// count