How do I get the position, rather than the value, of the highest one bit in integer? I know I can get the value like this:
// Prints 8; in 1101, the highest bit is the one denoting 8
int f = 13;
System.out.println("Highest: " + Integer.highestOneBit(f));
However, I'd like to get position of the highest one bit - in this case, it would be 4 (since 1000
in binary == 8
, the highest one bit is the fourth one).