Follow along with the video below to see how to install our site as a web app on your home screen.
Anmerkung: This feature may not be available in some browsers.
public static int log2(int v) {
return 31 - Integer.numberOfLeadingZeros(v);
}
Wobei mir daWenn es tatsächlich nur int sein soll, dann:
public static int log2(int v) {
return v == 0 ? Integer.MAX_VALUE : 31 - Integer.numberOfLeadingZeroes(v);
}
Ja, das hatte ich auch schon überlegt 🙂Hmmm, möglicherweise sollte man da eine ArithmeticException oder IllegalArgumentException werfen.