I want to find the most significant bit that is set to 1. I have tried every possible way from & to ORing all of the bits from 1 t
1
&
Not the most efficient, perhaps, but this should work::
public int firstBit(int i) { return i < 0 ? 31 : i == 0 ? 0 : Integer.toString(i, 2).length(); }