Here's a tough one(atleast i had a hard time :P):
find the index of the highest bit set of a 32-bit number without using any loops.
With recursion:
int firstset(int bits) { return (bits & 0x80000000) ? 31 : firstset((bits << 1) | 1) - 1; }
[31,..,0]
| 1
1
2.1m questions
2.1m answers
60 comments
57.0k users