I want to get the low 32 bit of a int64 as int32

前端 未结 5 1276
梦如初夏
梦如初夏 2021-01-04 05:02

I have an Int64 value, but I only need the lower 32 bits. Thus I want a quick way to get the Int32 value from the lower 32 bits of the Int64 value.

Thanks

5条回答
  •  渐次进展
    2021-01-04 05:41

    If you assign a int64 value into a int32 value, the compiler will automatically do that for you
    (as Steven Sudit mentioned):

    int64 val64 = ...;
    int32 val32 = ...;
    ...
    
    val32 = val64; // get the low 32 bits
    // or
    val32 = (val64 >> 32); // get the high 32 bits
    

    and because the compiler may display warnings you can specify the cast

    val32 = (int32)val64;
    

提交回复
热议问题