c/c++ left shift unsigned vs signed
问题 I have this code. #include <iostream> int main() { unsigned long int i = 1U << 31; std::cout << i << std::endl; unsigned long int uwantsum = 1 << 31; std::cout << uwantsum << std::endl; return 0; } It prints out. 2147483648 18446744071562067968 on Arch Linux 64 bit, gcc, ivy bridge architecture. The first result makes sense, but I don't understand where the second number came from. 1 represented as a 4byte int signed or unsigned is 00000000000000000000000000000001 When you shift it 31 times