retagged by
14,309 views
29 votes
29 votes

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?

  1. $0\text{x}6665$
  2. $0\text{x} 0001$
  3. $0\text{x} 4243$
  4. $0\text{x} 0100$
retagged by

6 Answers

Best answer
27 votes
27 votes

This question is poorly framed and has interpretation ambiguity. Refer to the discussion on this question in the below link :

https://cs.stackexchange.com/questions/135713/representation-of-unsigned-integer-on-a-little-endian-big-endian-computer

All kinds of “interpretations” are available in that discussion. 

The following is my interpretation of the question :

It is asking “which of the following choices represent(s) the unsigned integer on a little-endian computer?

Take Option $``\mathtt{0x6665}” :$

It is saying that $\mathtt{0x6665}$ is the representation of an integer on a little-endian computer, so, it means that the original number must have been $\mathtt{0x6566}.$ 

So, for the original number $\mathtt{0x6566} :$

  • On little endian(LE) $: \mathtt{0x6665}$ 
  • On Big endian(BE) $: \mathtt{0x6566}$

Clearly, $LE = 255 + BE$

Similarly, for $\mathtt{0x0100}.$ 

Take $\mathtt{0x0100} :$

It is saying that $\mathtt{0x0100}$ is the representation of an integer on a little-endian computer, so, it means that the original number must have been $\mathtt{0x0001}. $

So, for the number $\mathtt{0x0001} :$

  • On little endian(LE) $: \mathtt{0x0100}$
  • On Big endian(BE) $: \mathtt{0x0001}$

Clearly,$ LE = 255 + BE$

Similarly for $\mathtt{0x4243}$ and $\mathtt{0x0001},$ They do not satisfy $``LE = 255 + BE \;”$, So, answer is option A,D.

Refer to Slide 26 in the below article :

Nice Reference: https://www.cs.utexas.edu/~byoung/cs429/slides2-bits-bytes.pdf

$\textbf{Representing Integers:}$

int A = 15213;
int B = -15213;
long int C = 15213;

$$\qquad 15213_{10} = 0011101101101101_{2} = \text{3B6D}_{16}$$

$$\begin{array}{|c| c | c | c| } \hline & \textbf{Linux (little endian)} & \textbf{Alpha (little endian)} & \textbf{Sun (big endian)} \\\hline \mathtt{A} & \mathtt{6D \; 3B \; 00 \; 00} & \mathtt{6D\;3B\;00\;00} & \mathtt{00\;00\;3B\;6D} \\\hline \mathtt{B} & \mathtt{93\;C4\;FF\;FF} & \mathtt{93\;C4\;FF\;FF} & \mathtt{FF\; FF\; C4\;93} \\\hline \mathtt{C} & \mathtt{6D\;3B\;00\;00\;00\;00\;00\;00} & \mathtt{6D\;3B\;00\;00\;00\;00\;00\;00} & \mathtt{00\;00\;00\;00\;00\;00\;3B\;6D} \\\hline \end{array}$$ $\textbf{Byte Ordering Examples:}$

  1. $\text{Big Endian:}$ Most significant byte has lowest (first) address.
  2. $\text{Little Endian:}$ Least significant byte has lowest address.

$\text{Example:}$

  • Int variable $\mathtt{x}$ has $4$-byte representation $\mathtt{0x01234567}.$
  • Address gives by $\mathtt{\&x}$ is $\mathtt{0x100}.$

$\text{Big Endian:}$

$\begin{array}{|c|c|c|c|c|c|c|c|c|} \hline \textbf{Address:} & \quad & \quad &  \mathtt{0x100} & \mathtt{0x101} & \mathtt{0x102} & \mathtt{0x103} & & \\\hline \textbf{Value:}  &\quad & \quad & 01 & 23 & 45 & 67 &  \quad & \quad \\\hline \end{array}$

$\text{Little Endian:}$

$\begin{array}{|c|c|c|c|c|c|c|c|c|} \hline \textbf{Address:} & \quad & \quad &  \mathtt{0x100} & \mathtt{0x101} & \mathtt{0x102} & \mathtt{0x103} & & \\\hline \textbf{Value:}  &\quad & \quad & 67 & 45 & 23 & 01 &  \quad & \quad \\\hline \end{array}$

Note that different people are having different interpretations of this question. I have asked this question on cs.StackExchange, and you can read the discussion in the below link :

https://cs.stackexchange.com/questions/135713/representation-of-unsigned-integer-on-a-little-endian-big-endian-computer

edited by
10 votes
10 votes
Ans: B and C.
0x0001 (binary: 0000 0000    0000 0001 ),as the value is stored in little endian would amount to 2^8*1 which is 256, however the same sequence of bits stored in big endian would amount to 2^0*1 =1 , so the liitle endian rep-BE rep=256-1=255
0x4243, same calculations as above(trick: just swap the 8 bits and look at the data bit’s that are not matching ) in this case too the difference between the little endian and big endian representation happens to be 256-1=255 hence both B and C are correct, the value given by option A and D is -255 as for those representations the little endian has a lower value than big endian system,
PS: In a big endian system the leftmost byte (sequence of 8 bits) are the most significant bytes [this is similar to how we generally solve binary numbers], however in a little endian system the sequence of bytes to the extreme left are least signigicant , it can be termed as mirror image of bytes as present in a big endian system
8 votes
8 votes

$0\text{x}0001-$ On big endian computer (like humans read) this will read as $1$ and on little endian computer (lower byte comes at left most) this will read as $0\text{x}0100=256$ giving a difference of $255.$

Similarly, $0\text{x}4243$ also gives a difference of $255.$


Since, there is confusion regarding the meaning of the question, lets dissect the 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?

In the above question, the bold portion refers to the same thing. We have a $2-$ byte integer (say $X$ and this is represented on a little endian computer and this is now given in the options. So, lets consider option B for example. It is $0\text{x}0001$ which is the little endian representation. Its numerical is $00  + 0\text{x} 01 \times 256 = 256.$ That is, value of $X = 256$ on a little endian machine. Same byte sequence if read on a big endian machine will give $00 \times 256 + 01 = 1.$  That’s a difference of $256-1 = 255.$

edited by
8 votes
8 votes

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)

 

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)

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 (memory dump).

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

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)

edited by
Answer:

Related questions

20 votes
20 votes
3 answers
1
13 votes
13 votes
3 answers
2
Arjun asked Feb 18, 2021
4,753 views
If $x$ and $y$ are two decimal digits and $(0.1101)_2 = (0.8xy5)_{10}$, the decimal value of $x+y$ is ___________