[问题] bit shift << 的问题

楼主: michael47 (hitman)   2014-08-26 15:04:22
Platform: Linux GCC
Question:
unsigned int test_bits_1 = 0x00000001;
printf("test_bits_1 = 0x00000001, test_bits_1 << 32 = %X\n",
test_bits_1 << 32);
printf("0x01 << 32 = %X\n", 0x01 << 32);
输出结果
test_bits_1 = 0x00000001, test_bits_1 << 32 = 1
0x01 << 32 = 0
请问问题出在哪里?
我以为结果test_bits_1 << 32 = 0
程式码(Code):
unsigned int test_bits_1 = 0x00000001;
printf("test_bits_1 = 0x00000001, test_bits_1 << 32 = %X\n",
test_bits_1 << 32);
printf("0x01 << 32 = %X\n", 0x01 << 32);
作者: suhorng ( )   2014-08-26 16:25:00
undefined behavior when sizeof(int) = 4
楼主: michael47 (hitman)   2014-08-26 17:11:00
请问楼上的意思是说当type为int(4个bytes)会这样吗?请问楼上可以提供造成这样结果的资料来源吗?我已经找到答案了,感谢楼上suhorng的提醒

Links booklink

Contact Us: admin [ a t ] ucptt.com