"i want to count the number of set-bits in an interger!":
(can't take credit for this one):
Code:
public final static int getBits(int i) {
i = ((i & 0xaaaaaaaa) >> 1) + (i & 0x55555555);
i = ((i & 0xcccccccc) >> 2) + (i & 0x33333333);
i = ((i >> 4) + i) & 0x0f0f0f0f;
i += i >> 8;
i += i >> 16;
return i & 0xff;
}