-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLittleEndian_BigEndian.cpp
61 lines (58 loc) · 1.35 KB
/
LittleEndian_BigEndian.cpp
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
60
61
#include <iostream>
using namespace std;
/*
// Big endian machines:
// FIRST byte of binary representation of the multibyte data-type is stored first
// So "01" gets stored first
//
/ Little endian:
// LAST byte of binary representation of the multibyte data-type is stored first
// So "67" gets stored first
/
// Num = 0x01234567
//
// Big Endian:
// 0x100 0x101 0x102 0x103
// +-------+-------+-------+-------+
// | 0x01 | 0x23 | 0x45 | 0x67 |
// +-------+-------+-------+-------+
//
// Little Endian:
// 0x100 0x101 0x102 0x103
// +-------+-------+-------+-------+
// | 0x67 | 0x45 | 0x23 | 0x01 |
// +-------+-------+-------+-------+
//
// Num = 0x00000001
//
// Big Endian:
// 0x100 0x101 0x102 0x103
// +-------+-------+-------+-------+
// | 0x00 | 0x00 | 0x00 | 0x01 |
// +-------+-------+-------+-------+
// |
// &i
//
// Little Endian:
// 0x100 0x101 0x102 0x103
// +-------+-------+-------+-------+
// | 0x01 | 0x00 | 0x00 | 0x00 |
// +-------+-------+-------+-------+
// |
// &i
//
*/
// Bloomberg
int main()
{
unsigned int i = 1;
char *c = (char*)&i; // Storing the 0th byte of 'i' in 'c'
if (*c)
{
cout << "Little Endian" << endl;
}
else
{
cout << "Big Endian" << endl;
}
}