I need to write some logic to determine, given an even number, the highest power of two that evenly divides it. What is the maximum value of 2^n where Input % 2^n == 0?
IE:
Input -> Output
4 (0100) -> 4
8 (1000) -> 8
12 (1100) -> 4
14 (1110) -> 2
24 (11000) -> 8
etc....
It looks like there be some bitwise logic that may work out: when looking at the input in binary, the rightmost one bit appears to be solution. How do I determine this value in C? Is there another solution that may be easier?
Thanks- Jonathan