-
Notifications
You must be signed in to change notification settings - Fork 0
/
LittleEndian_Detector.c
59 lines (53 loc) · 1.66 KB
/
LittleEndian_Detector.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
53
54
55
56
57
58
59
/* -
* Copyright (c) 2006-2017 All rights reserved.
* Department of Information Security
* Sejong Univerity
*
* This code is contributed by Ki-Woong Park
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* Author : Ki-Woong Park Sejong University
* E-mail : [email protected]
*/
#include<stdio.h>
#include<stdlib.h>
int Test_Little_Endian();
int main()
{
printf(" Sejong University\n");
printf(" Department of Information Security\n");
printf("This program is intended to determine whether this computer is little endian or not.\n\n");
printf("Result: ");
if(Test_Little_Endian())
{
printf("This pc is on the little endian.\n");
}
else
{
printf("This pc is on the big endian.\n");
}
getchar();
return 0;
}
int Test_Little_Endian()
{
int num = 0x00FF;
int i = 0;
for(i = 0; i<2; i++)
{
printf("%p : ", &num +i);
printf("%x \n", *((unsigned char *)&num +i));
}
return (*((unsigned char*)&num) == 0xFF);
}