【发布时间】:2017-10-24 10:17:21
【问题描述】:
数据丢失对我来说没问题。
var temp1:Int32 = 45058
var temp2:Int32 = -20345
var temp3:Int32 = -40345
var temp4:Int16 = Int16(temp1)//overflow
var temp5:Int16 = Int16(temp2)//return wrog value
var temp6:Int16 = Int16(temp3)//overflow
也试过这个,但它也返回错误的值,这不是我想要的。
temp4 = Int16(temp1 & 0x0000ffff)//overflow
在我的 C 代码中,没有任何问题,因为 c 编译器是自己完成的。
【问题讨论】:
-
如果有符号 16 位整数的最大值为
32767,您打算如何将45058转换为有符号 16 位整数? -
@mag_zbc 这显然应该是截断强制转换,这在 C 或 Java 中会发生。