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