我知道這樣的話題被問了好幾次,但我的問題是關於整個32位int溢出。例如:我怎麼能檢測到32位的整數溢出
11111111111111111111111111111111 +
00000000000000000000000000000001 =
00000000000000000000000000000000 //overflow!
我發現topic有類似的問題,但這個算法並不完美。
11111111111111111111111111111111 +
00000000000000000000000000000000 =
00000000000000000000000000000000 //overflow!
有沒有簡單快捷的方法來檢查?
https://www.securecoding.cert.org/confluence/display/java/NUM00-J.+Detect+or+prevent+integer+overflow –