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?

Choose every correct option
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 AA and A+1A+1 consist of bytes B0B_0 and B1B_1, 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):

VLE=256⋅B1+B0V_{\text{LE}} = 256 \cdot B_1 + B_0

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):

VBE=256⋅B0+B1V_{\text{BE}} = 256 \cdot B_0 + B_1

We are given that VLE−VBE=255V_{\text{LE}} - V_{\text{BE}} = 255:

(256⋅B1+B0)−(256⋅B0+B1)=255(256 \cdot B_1 + B_0) - (256 \cdot B_0 + B_1) = 255
255⋅B1−255⋅B0=255255 \cdot B_1 - 255 \cdot B_0 = 255
B1−B0=1B_1 - B_0 = 1

Thus, for an unsigned integer on a little-endian computer, its high-order byte B1B_1 must exceed its low-order byte B0B_0 by exactly 1.

Check each option represented in hexadecimal as 0x[MSB][LSB], where MSB is B1B_1 and LSB is B0B_0:

  • Option A: 0x6665: B1=0x66=102B_1 = 0x66 = 102, B0=0x65=101B_0 = 0x65 = 101. Here B1−B0=102−101=1B_1 - B_0 = 102 - 101 = 1. This satisfies the condition!
  • Option B: 0x0001: B1=0x00B_1 = 0x00, B0=0x01B_0 = 0x01. Here B1−B0=−1≠1B_1 - B_0 = -1 \ne 1.
  • Option C: 0x4243: B1=0x42B_1 = 0x42, B0=0x43B_0 = 0x43. Here B1−B0=−1≠1B_1 - B_0 = -1 \ne 1.
  • Option D: 0x0100: B1=0x01B_1 = 0x01, B0=0x00B_0 = 0x00. Here B1−B0=1−0=1B_1 - B_0 = 1 - 0 = 1. This satisfies the condition!

Therefore, choices A and D are correct.

Final answer

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.