This code returns 0, where it should return 18446744073709551615, which should fit in a ulong? When I set it to iterate 63 (rather than 64) times I get 9223372036854775808, which is correct.
public static ulong Total()
{
ulong output = 1ul ;
for(var x = 0; x < 64; x++)
{
output *= 2;
}
return output;
}
You are calculating 2^64, which is not 18446744073709551615 but 18446744073709551616. You may notice that when you changed 64 to 63 you got 9223372036854775808 and not 9223372036854775807.