What you did by discarding long to short is the narrowing of the primitive transform that JLS covers , section 5.1.3 :
Narrowing the conversion of a signed integer to an integral type T simply discards everything except n bits of the least significant bit, where n is the number of bits used to represent type T. In addition to the possible loss of information about the value, a numerical value can lead to the sign of the resulting values โโwill differ from the sign of the input value.
The long 40002 is the following 64 bits:
00000000 00000000 00000000 00000000 00000000 00000000 10011100 01000010
The conversion only saves the lower 16 bits:
10011100 01000010
That the leading 1 interpreted in the 2 additions of the supplement as -2 ^ 15, and not + 2 ^ 15. This explains why there is a difference in 2 ^ 16, 65 536, in the long value and the short value.
source share