原码,反码,补码
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main() {
int a = 20;
int b = -10;
1 - 1;
return 0;
}
求当前机器的字节序
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
check_sys() {
int a = 1;
char* p = (char*)&a;
return *p;
}
int main() {
int ret = check_sys();
if (ret == 1) {
printf("小端\n");
}
else {
printf("大端\n");
}
return 0;
}
无符号
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main() {
char a = -1;
signed char b = -1;
unsigned char c = -1;
printf("a=%d,b=%d,c=%d",a,b,c);
printf("\n----------------------------\n");
char d = -128;
printf("%u\n", a);
return 0;
}
a=-1,b=-1,c=255
----------------------------
4294967295
|