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
1.4m articles
1.4m replys
5 comments
57.0k users