An array of 2 two byte integers is stored in big endian machine in byte addresses as shown below. What will be its storage pattern in little endian machine? Address Data 0 × 104 78 0 × 103 56 0 × 102 34 0 × 101 12
An array of 2 two byte integers is stored in big endian machine in byte addresses as shown below. What will be its storage pattern in little endian machine? Address Data 0 × 104 78 0 × 103 56 0 × 102 34 0 × 101 12 Correct Answer <p>0 × 104 56</p> <p>0 × 103 78</p> <p>0 × 102 12</p> 0 × 101 34
Concept -
- Little and big endian are two ways of storing multi-byte data-types like int, float, etc.
- In little endian machines, last byte of binary representation of the multi-byte data-type is stored first.
- On the other hand, in big endian machines, first byte of binary representation of the multi-byte data-type is stored first.
Explanation -
Given in the question is that each integer is of two bytes. For little endian-big endian, we will determine MSB and LSB of both the integers.
The big endian format,
|
104 |
103 |
102 |
101 |
|
78 |
56 |
34 |
12 |
|
MSB-1 |
LSB-1 |
MSB-2 |
LSB-2 |
MSB-1 refers to MSB of 1st integer.
For little endian, we simply have to reverse the exchange MSB with LSB and vice versa.
|
104 |
103 |
102 |
101 |
|
56 |
78 |
12 |
78 |
|
LSB-1 |
MSB-1 |
LSB-2 |
MSB-2 |
Hence, Option 3 is correct.
NOTE
if this was one integer with 4 bytes, then in little endian format, entire sequence would have been reversed.
মোঃ আরিফুল ইসলাম
Feb 20, 2025