In the following program, will repeated ~ and << operations converge to a negative value on all platforms?
#include <iostream>
int main()
{
int x{};
for(int i{}; i < 32; ++i) {
x = ~x;
x <<= 1;
std::cout << x << '\n';
}
}
My assessment is that it will because the left shift is not implementation defined. Would it be true to say that the only time it will not converge is if int
is larger than 32 bits?