< prev index next >

src/java.base/share/classes/java/lang/Integer.java

Print this page
rev 49267 : [mq]: 8199843-Optimize-Integer-Long-highestOneBit

*** 1572,1588 **** * of the highest-order one-bit in the specified value, or zero if * the specified value is itself equal to zero. * @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); } /** * Returns an {@code int} value with at most a single one-bit, in the * position of the lowest-order ("rightmost") one-bit in the specified --- 1572,1582 ---- * of the highest-order one-bit in the specified value, or zero if * the specified value is itself equal to zero. * @since 1.5 */ public static int highestOneBit(int i) { ! return i == 0 ? 0 : MIN_VALUE >>> numberOfLeadingZeros(i); } /** * Returns an {@code int} value with at most a single one-bit, in the * position of the lowest-order ("rightmost") one-bit in the specified
< prev index next >