2
$\begingroup$

This is a GATE 2021 exam 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?

A. 0x6665
B. 0×0001
C. 0×4243
D. 0×0100

According to me, answer should be A,D. But according to some of my colleagues, answer is B,C.

My logic for answer being A,D :
The question is asking “which of the following choices represent(s) the unsigned integer on a little endian computer?”

Take Option “0x6665” :

The question is saying that 0x6665 is the representation of some integer on a little endian computer, so, it means that the original number must have been 0x6566.
So, for the original number 0x6566 :
On little endian(LE) : 0x6665
On Big endian(BE) : 0x6566

Clearly, LE = 255 + BE

Similarly, for 0x0100. Take 0x0100 :
He is saying that 0x0100 is the representation of some integer on a little endian computer, so, it means that the original number must have been 0x0001.

So, for the number 0x0001 :
On little endian(LE) : 0x0100
On Big endian(BE) : 0x0001

Clearly, LE = 255 + BE

Similarly for 0x4243 and 0x0001, They do not satisfy “LE = 255 + BE” condition , So, answer should be option A,D.

For Reference, Refer Slide 26 in the below article :
https://www.cs.utexas.edu/~byoung/cs429/slides2-bits-bytes.pdf

$\endgroup$
1
  • $\begingroup$ Calling any given representation of a number original is original. $\endgroup$ – greybeard Feb 21 at 8:17
4
$\begingroup$

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

According to the dictionary, the definition of "numerical value" is "a real number regardless of its sign", in other words absolute value. Since the integer is unsigned, its numerical value is itself, and that will not change no matter how the integer is stored, little or big endian style, written on a napkin with lipstick in base seven, notches on a bedpost, or whatever. Therefore, the first line of the question is meaningless, which is always a nice start.

Additionally, the question confuses memory representation and integers. Two bytes in memory that look like (0x00,0x01) represent the integer 0x0100 in little-endian mode, but you can't say "let's add 255 to (0x00,0x01)" because (0x00,0x01) is not the number 0x0001 although it looks like it.

A correctly worded question would be:

"There are two bytes in memory. A big-endian cpu reads them with a uint16 load instruction and gets an uint16 value. A little-endian cpu reads the same two bytes and gets an uint16 value that is 255 higher than the big-endian cpu's value. What are the two bytes in memory?"

(One could also ask what uint16 one of the cpus gets)

Then it's pretty simple:

Memory    uint16     uint16
dump      read by LE read by BE
0x66 65   0x6566     0x6665
0x65 66   0x6665     0x6566    correct
0×00 01   0x0100     0x0001    correct
0×01 00   0x0001     0x0100
0×42 43   0x4342     0x4243    correct
0×43 42   0x4243     0x4342

According to me, answer should be A,D. But according to some of my colleagues, answer is B,C.

Having nuked the question, let's play jeopardy and try to figure out what question you and your colleagues are answering.

Basically, to misquote a famous crook, you're having a disagreement over what the word "represents" represents. One thinks it is the memory representation in little-endian (although it is written wrong in the question, and honestly if the word "memory" was mentioned it wouldn't hurt for ease of comprehension) and the other thinks it's the integer itself (probably because the 0x values are written as integers not bytes). So you're both picking from a different column of my table above.

We will have to wait for the end of the war between little endians and big endians to know what the peace treaty says about who's right.

Another way to not fix the question would be: If the memory representation of a 2-byte unsigned integer on a little endian computer looks like it is 255 more than that on a big endian computer to a human reading the memory bytes in big endian order, which of the following choices represent(s) the unsigned integer?

However, this reveals to all the rampant systemic endianness supremacy asserting that humans of the wrong endianness are lower-class citizens. This implicit endianness bias and oppression must stop! As of today, the DIE commitee dictates that everyone will switch to the more inclusive and safe middle-endianness, and both-endians colonizers will be sentenced to pay reparations to native middle-endians.

$\endgroup$
3
  • $\begingroup$ While your last paragraph could be meant as a joke, it is very unnecessary, and I would not like to be reminded of history, especially not on a site dedicated to Computer Science. Please consider removing it. $\endgroup$ – Shashank V M Mar 1 at 14:39
  • $\begingroup$ I can see an attempt at levity there, but one made in bad taste. @bobflux, please remember that invoking associations with colonialism also invokes memories of violence and racism. The fact that "endian" and "Indian" are phonetically close also doesn't help. As such, to avoid making people unnecessarily uncomfortable I recommend you remove that paragraph, or replace it with another approach to making your point (I honestly can't make one out, sorry). $\endgroup$ – Raphael Mar 4 at 11:15
  • $\begingroup$ "Endian" and "Indian", good find! lol $\endgroup$ – bobflux Mar 4 at 12:09
1
$\begingroup$

In little endian, the least significant byte is the first you read. It means that 0x6665 (LE) should be read as $$0\text{x}6665 \text{ (LE)} =(0\text{x}66) + (0\text{x}65) \times 256 = 102 + 101\times256 = 25958$$ If you read 0x6665 in big endian, you read the most significant byte first, and you get : $$0\text{x}6665 \text{ (BE)} = (0\text{x}66) \times 256 + (0\text{x}65) = 102\times 256 + 101 =26213= 25958 +255$$ We have LE = BE - 255, so answer A is incorrect. The right answers are B and C.

$\endgroup$
0
$\begingroup$

What’s interesting is that you don’t even need to know how bigendian and littlendian numbers are stored in memory, just that they are stored in opposite order!

Assume that two bytes aa and bb are stored in memory, and interpreting these bytes as a littleendian 16 bit integer gives a value of 0xaabb = 256a + b. Interpreting the same two bytes as bigendian would give a value 0xbbaa = a + 256b.

You are told the first value is 255 larger than the second, so 256a + b = a + 256b + 255, or 255a = 255b + 255, or a = b + 1. 0x0100, 0x4342 etc. would be solutions.

That said, whoever wrote the question is showing a very muddled thinking about what bigendian and littleendian means. Numbers are not bigendian or littleendian. They are just numbers. The same number will have the same value on any computer. On a computer where you can access memory in units less than 16 bits, you can store a 16 bit integer and read the bytes individually. The result is called the “representation” of the integer. This representation can be different, the numbers are not. And there is no reason why computers would be restricted to just two representations. A computer could store all the even bits in one byte and all the odd bits in the other byte, for example.

$\endgroup$
1
  • $\begingroup$ Do you mean that "the numerical value of a 2-byte unsigned integer on a little-endian machine remains same on a big-endian machine? Yes, I agree to that. I see no reason why the question could have been more specific to what it wanted to ask. $\endgroup$ – Arjun Suresh Feb 21 at 23:30
0
$\begingroup$

The way the question is framed, I do not agree with the concept at all.

A number is after all a number, be it big endian or little endian.

The main concept of Big endian or little endian is as follows:

Big Endian: In computer system which is big endian, the lower order byte of the data in the memory maps to the higher (big) order byte of the registers in CPU. (see figure below)

Big Endian

Little Endian: In computer system which is little endian, the lower order byte of the data in the memory maps to the lower (little) order byte of the registers in CPU. (see figure below)

Little Endian

As such, the whatever be the system type (Big or little endian) the number should actually be the same in the registers in the CPU, as the ALU knows one and only one representation of a number which is binary equivalent of a number.

The difference arises in the way the number is STORED IN THE MAIN MEMORY.

This makes the things a bit ambiguous.

Assuming they are taking about the representation of the number in main memory.

i.e. $ \text{Memory[1]Memory[0]}$ [A complete word] (see figure below)

Memory word

This ambiguity can be resolved by the way the question is asked.

From the above concept we can see that: what ever be byte sequence we assume for LITTLE ENDIAN, that byte sequence shall be reversed for BIG ENDIAN.

Option A: $$0x6665–0x6566=FF=(255)_{10}$$

Option D: $$0x0100–0x0001=FF=(255)_{10}$$

In other cases, (option B or C, assuming the given option and reversing the byte sequence gives a number greater than the option, as per the question the little endian value is greater)

$\endgroup$
0
$\begingroup$

2,3 is answer.

If you split hex number into bytes.. In hexa representation, each digit corresponds to 4 binary digits.... (I.e 2 hex digits =8 bits= 1 byte).

If little endian representation is

(byte-n).....(byte-2)(byte-1) then

Big endian representation is

(byte-1)(byte-2).....(byte-n)

With in the byte no change in bit sequence.

A) 0x0001

Little endian 0x0001 gives you 01 as first byte and 00 as second byte.... So corresponding big endian representation is 0x0100. Hex (0x0001) is equal to 1 in decimal Hex(0x0100) is equal to 256 in decimal. Their difference is -255.

B) 0x6665

Little endian 0x6665 gives you 65as first byte and 66 as second byte.... So corresponding big endian representation is 0x6566. Hex (0x6665) is equal to 26213 in decimal Hex(0x6566) is equal to 25958 in decimal. Their difference is 255.

C) 0x0100

Little endian 0x0100 gives you 00 as first byte and 01 as second byte.... So corresponding big endian representation is 0x0100 Hex(0x0100) is equal to 256 in decimal. Hex (0x0001) is equal to 1 in decimal

Their difference is 255.

D)0x4243

Little endian 0x4243 gives you 43 as first byte and 42 as second byte.... So corresponding big endian representation is 0x4342 Hex(0x4243) is equal to 16963 in decimal. Hex (0x4342) is equal to 17218 in decimal. Their difference is -255.

So...2,3 is answer

( tip: the little endian value of a 4 digit hexnumber is more, if number formed by first 2 hex digits is more than the number formed by the last two digits of the number)

$\endgroup$
1
  • 1
    $\begingroup$ 2,3 is answer neither 2 nor 3 or 2,3 appears anywhere. In contrast to, ominously, 42. $\endgroup$ – greybeard Feb 24 at 17:46
0
$\begingroup$

The answer is A and D. The 16 bit values are printed by the LE machine. The extra 255 is visible.only on the big endian machine. The question could have been made more confusing by inducing doubt about nibble (4 bit) location, but the teacher carefully avoided all ambiguity by using a difference where two consecutive nibble are identical. In other words, 255 is chosen so that all 8 bits, whether seen as D7-D0 or D15-D8 are the same, namely all "1" in binary. 0x6665,0x65,0x66+0x00FF=0x6665 0x0001,0x01,0x00+0x00FF=0x01FF 0x4243,0x43,0x42+0x00FF=0x4441 0x0100,0x00,0x01+0x00FF=0x0100

The question appears as clear as cristal* to me. *California says cristal may contain lead which can be harmful if you are pregnant. Ask your doctor if you can have little endian mixed with your big endian.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.