jdk的Integer.java中的一个方法,实在看不懂,怎么移位就算出了一个数字的二进制原码中有几个1,那位大牛能通俗的解释下下面这段代码?
/**
* Returns the number of one-bits in the two's complement binary
* representation of the specified <tt>int</tt> value. This function is
* sometimes referred to as the <i>population count</i>.
*
* @return the number of one-bits in the two's complement binary
* representation of the specified <tt>int</tt> value.
* @since 1.5
*/
public static int bitCount(int i) {
// HD, Figure 5-2
i = i - ((i >>> 1) & 0x55555555);
i = (i & 0x33333333) + ((i >>> 2) & 0x33333333);
i = (i + (i >>> 4)) & 0x0f0f0f0f;
i = i + (i >>> 8);
i = i + (i >>> 16);
return i & 0x3f;
}