Question
If the numerical value of a 2-byte unsigned integer on a little endian computer is 255 more than that on a big endian computer, which of the following choices represent(s) the unsigned integer on a little endian computer?
Official answer and solution
- Official answer
- A and D
- From
- Official GATE 2021 answer key
Solution
Express the value of a 2-byte integer in terms of its memory bytes under little-endian and big-endian conventions, and solve for the byte difference.
Let the 2-byte integer stored in memory at addresses and consist of bytes and , respectively.
In a Little Endian (LE) architecture, the byte at the lower address is the least significant byte (LSB), and the byte at the higher address is the most significant byte (MSB):
In a Big Endian (BE) architecture, the byte at the lower address is the most significant byte (MSB), and the byte at the higher address is the least significant byte (LSB):
We are given that :
Thus, for an unsigned integer on a little-endian computer, its high-order byte must exceed its low-order byte by exactly 1.
Check each option represented in hexadecimal as 0x[MSB][LSB], where MSB is and LSB is :
- Option A:
0x6665: , . Here . This satisfies the condition! - Option B:
0x0001: , . Here . - Option C:
0x4243: , . Here . - Option D:
0x0100: , . Here . This satisfies the condition!
Therefore, choices A and D are correct.
A, D
The answer is the one in the official GATE answer key. The solution is this site's own explanation.
Source
- Paper
- GATE 2021 Computer Science and Information Technology - Session 2 (CS2)
- Question
- 54 of 65, printed as CS Q.44
- Section
- Computer Science and Information Technology
Report an error in this question
GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.