6,934 views

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$

### 5 Comments

How many marks was alloted for this question?
@ACCURACY by default it is little endian
Conceptually this question is very easy, but if we talj about time, this question is really very time consuming.
2 Marks

## 8 Answers

Best answer

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 :

$\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

by
29 46 152

### 5 Comments

Sir açcording to official answer key A,D are correct.. i marked B,C :(
It will be challenged. We will have to see final key for this. I think it is unlikely they will change it, But let’s see.
Did they change?

If not then what is the solution,

If yes, then ok.
Final answer of GATE was option A,D only. They did not change it.
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

$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.$

by
513 802 798

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)

by
1

There are already good answers posted but let me share the “quickest” approach to the question.

First, let’s discuss the concept, and then we’ll dive straight to the question.

Concept :

Let’s take a binary number i.e. 0101 011

Ques) How do we write this in decimal format?

Ans) Let’s take 0101 and left shift it by 3, we get 0101 000 and we can write it in decimal as $5\times 2^{3}$

Now, add 011 i.e. $3$ to it.

Finally, we get $5\times 2^{3} + 3$

Here, we apply this concept to the question as well,

Given in the question, 2 byte integer format,

Little Endian :

 x y

where x and y represents decimal value corresponding to their respective binary number

So, in decimal, we get $x\times 2^{8} + y$     _______(1)

Big Endian :

 y x

where x and y represents decimal value corresponding to their respective binary number

So, in decimal, we get $y\times 2^{8} + x$   ________(2)

Now, Question says

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”.

That means, Value of Little Endian = Value of Big Endian + 255

From (1) and (2), we get

$x\times 2^{8} = y\times2^{8} + 255$

$256x + y = 256y + x + 255$

$x - y =1$

That means, we've to check only decimal values represented by x and y respectively and check whether their difference is 1 or not.

Given in the question, options are represented in “Little endian format” , thus, we can say

x represents MSB and y represents LSB.

(refer above concept)

Let’s check options now :

Option A:

$0x6665 = 01100110 01100101$

$x = 01100110 = (102)_{10}$ ; $y = 01100101 = (101)_{10}$

$x - y = 1$

Therefore, Option A is valid.

Option B:

$0x0001 = 00000000 00000001$

$x = 00000000 = (0)_{10}$ ; $y = 00000001 = (1)_{10}$

$x - y = -1$

Therefore, Option B is not valid.

Option C:

$0x4243 = 01000010 01000011$

$x = 01000010 = (66)_{10}$ ; $y = 01000011 = (67)_{10}$

$x - y = -1$

Therefore, Option C is not valid.

Option D:

$0x0100 = 00000001 00000000$

$x = 00000001 = (1)_{10}$ ; $y = 00000000 = (0)_{10}$

$x - y = 1$

Therefore, Option D is valid.

Hence, Option A and Option D are correct.

by
1

### 2 Comments

Great :)
Great explanation.

The question is not well framed as if a unsigned number is stored in Little Endian computer it will be read in Little Endian format (higher memory location to lower memory location).

Example: let the original number be 6665, then in Little Endian computer it will be stored as 6566 and the reading order will be 6665.

AND,

If a unsigned number is stored in Big Endian computer it will be read in Big Endian format (lower memory location to higher memory location).

Example: let the original number be 6665, then in Big Endian computer it will be stored as 6665 and the reading order will be 6665.

So, final output is same.

CORRECT FRAMING OF QUESTION MAY BE LIKE THIS:

"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?"(source: https://cs.stackexchange.com/questions/135713/representation-of-unsigned-integer-on-a-little-endian-big-endian-computer)

Now,

option A,

let consider the default system is in little endian format and number is 6665 in this format, so original number would be 6566

little endian access sequence –> (6665)base16 = (25958)base10

big endian access sequence –> (6566)base16 = (26213)base10

clearly, little endian = big endian+255,

similarly, option D will satisfy.

So, A and D will be answer.

by
1 5 10

The question is not well framed as if a unsigned number is stored in Little Endian computer it will be read in Little Endian format (higher memory location to lower memory location).

Example: let the original number be 6665, then in Little Endian computer it will be stored as 6566 and the reading order will be 6665.

AND,

If a unsigned number is stored in Big Endian computer it will be read in Big Endian format (lower memory location to higher memory location).

Example: let the original number be 6665, then in Big Endian computer it will be stored as 6665 and the reading order will be 6665.

So, final output is same.

CORRECT FRAMING OF QUESTION MAY BE LIKE THIS:

"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?"(source: StackExchange)

Now,

option A,

let consider the default system is in little endian format and number is 6665 in this format, so original number would be 6566

little endian access sequence –> (6665)base16 = (25958)base10

big endian access sequence –> (6566)base16 = (26213)base10

clearly, little endian = big endian+255,

similarly, option D will satisfy.

So, A and D will be answer.

by
1 5 10

The question is not well framed as if a unsigned number is stored in Little Endian computer it will be read in Little Endian format (higher memory location to lower memory location).

Example: let the original number be 6665, then in Little Endian computer it will be stored as 6566 and the reading order will be 6665.

AND,

If a unsigned number is stored in Big Endian computer it will be read in Big Endian format (lower memory location to higher memory location).

Example: let the original number be 6665, then in Big Endian computer it will be stored as 6665 and the reading order will be 6665.

So, final output is same.

CORRECT FRAMING OF QUESTION MAY BE LIKE THIS:

"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?"(source: StackExchange)

Now,

option A,

let consider the default system is in little endian format and number is 6665 in this format, so original number would be 6566

little endian access sequence –> (6665)base16 = (25958)base10

big endian access sequence –> (6566)base16 = (26213)base10

clearly, little endian = big endian+255,

similarly, option D will satisfy.

So, A and D will be answer.

by
1 5 10
Answer:

10 votes
3 answers
1
4,562 views
10 votes
3 answers
2
2,104 views
15 votes
3 answers
3
2,981 views
10 votes
2 answers
4
4,732 views