int main()
{
short a=-1;
unsigned int b=a;
int c=a;
printf("%xn", b);
printf("%dn", c);
a=1;
b=a;
c=a;
printf("%xn", b);
printf("%dn", c);
return 0;
}
输出为:
ffffffff
-1
1
1
说明,把short型数据赋值给int或者unsigned int型数据时,如果short型数据是负的,则扩展的比特位全是1,;如果short型数据是正的,则扩展的比特位全是0.
代码如下:
#include stdio.h
int main()
{
unsigned short a=-1;
unsigned int b=a;
int c=a;
printf("%xn", b);
printf("%dn", c);
a=1;
b=a;
c=a;
printf("%xn", b);
printf("%dn", c);
return 0;
}
输出为:
ffff
65535
1
1
说明,把unsigned short型数据赋值给int或者unsigned int型数据时,则扩展的比特位全是0