private int GetNumBitsSet(long bits) { int ret = 0; for (int i = 0; i < 64; i++) { if ((bits & ((long)1 << i)) != 0) ret++; } return ret; }