The only sane way to count the number of 1 bits in a byte is to use a lookup table: return table[result]; On an intel chip this produces ONE opcode: XLAT