在(char)0xff的左移8,并将其转换为int,我们得到-256或0xffffff00.有人可以解释为什么会这样吗?
#include <stdio.h>
int main (void)
{
char c = 0xff;
printf("%d %x\n", (int)(c<<8),(int)(c<<8));
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出是
-256 ffffff00
Run Code Online (Sandbox Code Playgroud)