public static bool BitScanReverse(out int index, ulong mask) { index = 0; while (mask > 1) { mask >>= 1; index++; } return mask == 1; }