Checks if n is potĂȘncia de 2
static bool isPowerOf2(int n) { if (n <= 0) return false; return (n & (n - 1)) == 0; }