This question is not about how a long should be correctly cast to an int, but rather what happens when we incorrectly cast it to an int.
So conside
The low 32 bits of the long
are taken and put into the int
.
Here's the math, though:
long
values as 2^64
plus that value. So -1
is treated as 2^64 - 1. (This is the unsigned 64-bit value, and it's how the value is actually represented in binary.)int
.)