Could someone explain me why the following computation overflows?
938372878L | (1 << 31) //results to -1209110770
It behaves as if the number were integer.
Could someone explain me why the following computation overflows?
938372878L | (1 << 31) //results to -1209110770
It behaves as if the number were integer.
1
is an int
literal, which is why (1 << 31)
overflows. You should change it to 1L
for it to be treated as long
:
938372878L | (1L << 31)
This results in
3085856526