June 2nd, 2011 0 comments

Given a 32 bit 2's complement number and the bitwise operation set & (and), | (or), ^ (xor), << and > (left and right shifting) define an equation or algorithm to count the number of bits which are set to 1 in the string without looping structures. Registers (variables) are allowed.

In other words: write the following C function without loops:

int set_bits_count(int input) {