<>数据在整数中的存储

1.源码，反码，补码

int main() { int a = 20; //00000000000000000000000000010100-源码,反码,补码 //换成十六进制序列
//0x000014 int b = -10; //10000000000000000000000000000000-源码
//11111111111111111111111111110101-反码 //11111111111111111111111111110110-补码
//fffffff6 return 0; }

a的内存

b的内存

<>字节序

int main() { int a = 1; char *p = (char*)&a; if (*p == 1) { printf("小端"); }
else { printf("大端"); } return 0;

int main() { char a = -1; //1000000000000000000000000000001-源码
//1111111111111111111111111111110-反码 //1111111111111111111111111111111-补码
//11111111-a //又以整型的方式打印，整型提升，按符号位补1 //1111111111111111111111111111111
//1111111111111111111111111111110 //1000000000000000000000000000001 //-1 signed
char b = -1; unsigned char c = -1; //11111111-c //对无符号位整型提升，高位补0
//0000000000000000000000011111111 printf("%d %d %d", a, b, c); return 0; }

int main() { int i = -20; unsigned int j = 10;
//10000000000000000000000000010100-补码 //11111111111111111111111111101011-反码
//11111111111111111111111111101100-源码 //00000000000000000000000000001010
//11111111111111111111111111110110//i+j //11111111111111111111111111110101//反码
//10000000000000000000000000001010 printf("%d", i + j); return 0; } int main() {
char a = -128; //1000000000000000000000010000000
//1111111111111111111111101111111 //1111111111111111111111110000000 //10000000-a
//%u-无符号整数 //1111111111111111111111110000000-补码 // //%u无符号整型 printf("%u\n", a);
return 0; } #include<stdio.h> int main() { char a[1000]; int i; for(i=0; i<1000;
i++) { a[i] = -1-i; } printf("%d",strlen(a)); return 0; }

Toolsou
API参考文档