In fact, this question can be simplified and directly
Console.Write("{0}",(short)60000);
Underlying reasons
When a variable is defined as short型的时候,其全称是有符号短整数型,这种类型占用2个字节,即word型,其范围是0x0000到0xffff,其中0x0000到0x7fff的最高为0,代表其为正数,0x7fff到0xffff最高为1,代表其为负数。 ok,那么十进制的60000,即十六进制的EA60, it is obviously a negative number, and it is originally a negative number.
Expand
If the type here is changed to unsigned short,那么输出的结果依然为60000.
In Java, the size range of short is: -32 768 to 32 767. Because your Add result 60000 is obviously out of bounds (32767), it will cause an error when casting to short type. It should be changed to
Simplify
In fact, this question can be simplified and directly
Underlying reasons
When a variable is defined as
short
型的时候,其全称是有符号短整数型
,这种类型占用2个字节,即word
型,其范围是0x0000
到0xffff
,其中0x0000
到0x7fff
的最高为0,代表其为正数,0x7fff
到0xffff
最高为1,代表其为负数。ok,那么十进制的
60000
,即十六进制的EA60
, it is obviously a negative number, and it is originally a negative number.Expand
If the type here is changed to
unsigned short
,那么输出的结果依然为60000
.Memory out of bounds
In Java, the size range of short is: -32 768 to 32 767. Because your Add result 60000 is obviously out of bounds (32767), it will cause an error when casting to short type. It should be changed to