forked from taniadovzhenko/CppPracticum
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask1.3.20.c
More file actions
45 lines (32 loc) · 721 Bytes
/
task1.3.20.c
File metadata and controls
45 lines (32 loc) · 721 Bytes
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
#include <stdio.h>
#include <stdint.h>
int endianness(){
uint32_t num = 0x01020304;
uint32_t b1,b2,b3,b4;
b1 = num & 255;
b2 = (num>>8) & 255;
b3 = (num>>16) & 255;
b4 = num>>24;
printf("%x, %x ,%x, %x\n",b1,b2,b3,b4);
if(b1==4 && b4==1){
if(b2==3 && b3==2){
printf("little-endian");
return 1;
}
else if (b2==2 && b3==3){
printf("middle-endian");
return 2;
}
printf("unknown type");
return -1;
}
if(b1==1 && b4==4 && b2==3 && b3==2) {
printf("big-endian");
return 3;
}
printf("unknown type");
return -1;
}
int main(){
endianness();
}