A neater (imo) way of writing that formula is
x = ((2 ^ n) - 1)(2 ^ (n - 1))
But that is only going to hit the even perfect numbers. There still might be odd perfect numbers out there. Nobody knows. Brute force checking has shown there are no odd perfect numbers that fit in 64 bits. But relying on this previously-done brute force checking would be just as bad as writing the known perfect numbers out directly in code, no? ;-)