-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsize.c
52 lines (36 loc) · 1.23 KB
/
size.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <stdint.h>
#include <stdio.h>
void print_as_bin(char c) {
for(int place = 128; place > 0; place /= 2) {
if((c & place) == 0) printf("0");
else printf("1");
}
}
int main() {
printf("sizeof(char): %ld\n", sizeof(char));
printf("sizeof(int8_t): %ld\n", sizeof(int8_t));
printf("sizeof(uint8_t): %ld\n", sizeof(uint8_t));
printf("sizeof(int16_t): %ld\n", sizeof(int16_t));
printf("sizeof(uint16_t): %ld\n", sizeof(uint16_t));
printf("sizeof(int32_t): %ld\n", sizeof(int32_t));
printf("sizeof(int64_t): %ld\n", sizeof(int64_t));
printf("sizeof(int): %ld\n", sizeof(int));
char c = 128;
int32_t i = 32;
char c2 = c + 1;
printf("sizeof(c): %ld\n", sizeof(c));
printf("sizeof(i): %ld\n", sizeof(i));
printf("sizeof(c * 4000): %ld\n", sizeof(c * 4000));
printf("sizeof(c + 1): %ld\n", sizeof(c + 1));
printf("sizeof(c2): %ld\n", sizeof(c2));
char s = 200;
unsigned char u = 200;
printf("s: ");
print_as_bin(s);
printf("\t\tu: ");
print_as_bin(u);
printf("\n");
printf("s as hhx: %hhx\t\tu as hhx: %hhx\n", s, u);
printf("s as x: %x\tu as x: %x\n", s, u);
printf("s < 127: %d u < 127: %d\n", s > 127, u > 127);
}