BitCount Method
问题 Can anyone Explain this bitcount method. public static int bitCount(int i) { // Hacker's Delight, Figure 5-2 i -= (i >> 1) & 0x55555555; i = (i & 0x33333333) + ((i >> 2) & 0x33333333); i = ((i >> 4) + i) & 0x0F0F0F0F; i += i >> 8; i += i >> 16; return i & 0x0000003F; } 回答1: It's based on three observations, The bitcount of a single bit is that bit itself. The bitcount of the concatenation of two bitstrings is the sum of their bitcounts. The bitcount of any string takes no more bits than that