When an int is cast to a short and truncated, how is the new value determined?

后端 未结 6 467
借酒劲吻你
借酒劲吻你 2020-12-01 13:53

Can someone clarify what happens when an integer is cast to a short in C? I\'m using Raspberry Pi, so I\'m aware that an int is 32 bits, and theref

6条回答
  •  再見小時候
    2020-12-01 14:18

    sx value will be the same as 2 least significant bytes of x, in this case it will be 0x8642 which (if interpreted as 16 bit signed integer) gives -31166 in decimal.

提交回复
热议问题