Nic*_*kis 27
如果将int64值分配给int32值,编译器将自动为您执行此操作
(如Steven Sudit所述):
int64 val64 = ...;
int32 val32 = ...;
...
val32 = val64; // get the low 32 bits
// or
val32 = (val64 >> 32); // get the high 32 bits
Run Code Online (Sandbox Code Playgroud)
并且因为编译器可能会显示警告,您可以指定强制转换
val32 = (int32)val64;
Run Code Online (Sandbox Code Playgroud)
做这样的事情:
long tempLong = ((yourLong >> 32) << 32); //shift it right then left 32 bits, which zeroes the lower half of the long
int yourInt = (int)(yourLong - tempLong);
Run Code Online (Sandbox Code Playgroud)
这可能不是最紧凑的方式,但它似乎是我最可读的.以下代码将提取long的高半:
long tempLong = (int)(yourLong >> 32);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
34816 次 |
最近记录: |