Counting the number of ones in the binary representation of an int. Here are the 32 bits of a normal int n = ABCDEFGHIJKLMNOPQRSTUVWXYZabcdef 0x55555555 = 01010101010101010101010101010101 n & 0x55555555 and (n >> 1) & 0x55555555 are 0B0D0F0H0J0L0N0P0R0T0V0X0Z0b0d0f and 0A0C0E0G0I0K0M0O0Q0S0U0W0Y0a0c0e Add those two together, and all the bit sums A+B, C+D, E+F, G+H, ..., e+f will be 0, 1, or 2, and will fit exactly into the two bits available to them So after n = (n & 0x55555555) + ((n >> 1) & 0x55555555); n could be written as AACCEEGGIIKKMMOOQQSSUUWWYYaaccee where AA represents the original bits A+B CC represents the original bits C+D EE represents the original bits E+F etc. Next 0x33333333 = 00110011001100110011001100110011 n & 0x33333333 and (n >> 2) & 0x33333333 are 00CC00GG00KK00OO00SS00WW00aa00ee and 00AA00EE00II00MM00QQ00UU00YY00cc Add those two together, and all the bit sums AA+CC, EE+GG, II+KK, ..., ee+cc will be 0, 1, 2, 3, or 4 and will fit easily into the four bits available to them So after n = (n & 0x33333333) + ((n >> 2) & 0x33333333); n could be written as AAAAEEEEIIIIMMMMQQQQUUUUYYYYcdef where AAAA represents the original bits A+B+C+D EEEE represents the original bits E+F+G+H IIII represents the original bits I+J+K+L etc. just repeat three more times for a total of n = (n & 0x55555555) + ((n >> 1) & 0x55555555); n = (n & 0x33333333) + ((n >> 2) & 0x33333333); n = (n & 0xFFFFFFFF) + ((n >> 4) & 0xFFFFFFFF); n = (n & 0x00FF00FF) + ((n >> 8) & 0x00FF00FF); n = (n & 0x0000FFFF) + ((n >> 16) & 0x0000FFFF); and n ends up as the sum of its own original bits.