[問題] bit shift << 的問題

看板C_and_CPP (C/C++)作者 (hitman)時間11年前 (2014/08/26 15:04), 11年前編輯推噓1(103)
留言4則, 2人參與, 最新討論串1/2 (看更多)
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); -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 118.166.2.127 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1409036665.A.B8D.html ※ 編輯: michael47 (118.166.2.127), 08/26/2014 15:09:46 ※ 編輯: michael47 (118.166.2.127), 08/26/2014 15:11:28

08/26 16:25, , 1F
undefined behavior when sizeof(int) = 4
08/26 16:25, 1F

08/26 17:11, , 2F
請問樓上的意思是說當type為int(4個bytes)會這樣嗎?
08/26 17:11, 2F

08/26 17:12, , 3F
請問樓上可以提供造成這樣結果的資料來源嗎?
08/26 17:12, 3F

08/26 17:37, , 4F
我已經找到答案了,感謝樓上suhorng的提醒
08/26 17:37, 4F
文章代碼(AID): #1J_35vkD (C_and_CPP)
討論串 (同標題文章)
文章代碼(AID): #1J_35vkD (C_and_CPP)