How to find the largest power of two divisor of a given integer? Given an integer $x$, I need to find the largest power of two $p = 2^n$ that divides $x$ such that the remainder is zero.
When $x$ is zero, the algorithm should return zero. For odd numbers, it should return one, since the largest power of two that divides these numbers is $2^0$.
How to write an algorithm for this? (any programming language would do, or pseudocode)
You just need to count the number of $0$ at the end of the binary encoding of $x$.