Office Riddle 06-01-11

June 2nd, 2011

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) {

}

Keywords:
puzzle,bitwise,c

0 replies

New comments are disabled.