In C Left shift (char) 0xFF by 8 and cast it to int

后端 未结 4 1204
再見小時候
再見小時候 2020-12-17 17:26

On left shift of (char) 0xff by 8 and casting it to int we get -256 or 0xffffff00. Can somebody explain why this should happen?

#include 
int         


        
4条回答
  •  伪装坚强ぢ
    2020-12-17 17:41

    char is nothing but signed char. So char c = 0xFF will be -1 . When you left shift -1 by 8 bits you get -256.

提交回复
热议问题