--- a/src/java.base/share/classes/java/lang/Integer.java Mon Mar 26 16:24:16 2018 -0700
+++ b/src/java.base/share/classes/java/lang/Integer.java Mon Mar 26 17:30:14 2018 -0700
@@ -1574,13 +1574,7 @@
* @since 1.5
*/
public static int highestOneBit(int i) {
- // HD, Figure 3-1
- i |= (i >> 1);
- i |= (i >> 2);
- i |= (i >> 4);
- i |= (i >> 8);
- i |= (i >> 16);
- return i - (i >>> 1);
+ return i & (MIN_VALUE >>> numberOfLeadingZeros(i));
}
/**
--- a/src/java.base/share/classes/java/lang/Long.java Mon Mar 26 16:24:16 2018 -0700
+++ b/src/java.base/share/classes/java/lang/Long.java Mon Mar 26 17:30:14 2018 -0700
@@ -1719,14 +1719,7 @@
* @since 1.5
*/
public static long highestOneBit(long i) {
- // HD, Figure 3-1
- i |= (i >> 1);
- i |= (i >> 2);
- i |= (i >> 4);
- i |= (i >> 8);
- i |= (i >> 16);
- i |= (i >> 32);
- return i - (i >>> 1);
+ return i & (MIN_VALUE >>> numberOfLeadingZeros(i));
}
/**