Find the highest power of two that divides x
, a 64-bit integer, or return -1.
The zero case is not defined, since it dives any power of two, so your method can return any number.
I tried using the BigInteger.getLowestSetBit()
for this, it returns the right answer but it's far from being optimal.
Example: Input -> output
- 3 -> -1
- 6 -> 1
- 4256 -> 5