int count8bit(unsigned char v) { unsigned count = (v & 0x55) + ((v >> 1) & 0x55); count = (count & 0x33) + ((count >> 2) & 0x33); return (count & 0x0f) + ((count >> 4) & 0x0f); } int count16bit(unsigned short v) { unsigned short count = (v & 0x5555) + ((v >> 1) & 0x5555); count = (count & 0x3333) + ((count >> 2) & 0x3333); count = (count & 0x0f0f) + ((count >> 4) & 0x0f0f); return (count & 0x00ff)