-10用16进制输出为何为ffffff6

#include <stdio.h>

int main()

{

    short int x = -10;

    // 原码 - 1000 0000 0000 1010

    // 反码 - 1111 1111 1111 0101

    // 补码 - 1111 1111 1111 0110

    //         F    F    F    6(我以为的结果)

    // 结果 - fffffff6, 好像占用4个字节

    printf("%x\n", x);

}

刚开始看C语言,不太明白
求解,谢谢诸位

智慧大石
浏览 665回答 2
2回答

BIG阳

#include <stdio.h>int main(void) {&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; char a=-10,b=1,e=2,d=4;&nbsp; &nbsp; long long c=-10;&nbsp; &nbsp; int sizea=sizeof(a);&nbsp; &nbsp; int sizec=sizeof(c);&nbsp; &nbsp; printf("%x,%d\n%x,%d\n",a,sizea,c,sizec);&nbsp; &nbsp; printf("%x,%d\n%x,%d",*((unsigned int*)&a),sizea,*((unsigned int*)&c),sizec);&nbsp; &nbsp; return 0;}
打开App,查看更多内容
随时随地看视频慕课网APP