retagged by
14,326 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

6 votes
6 votes

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 : 

<---------------------1 byte-------------------><-----------------------1 byte-------------------->
                         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 :

<---------------------1 byte-------------------><-----------------------1 byte-------------------->
             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.


 

0 votes
0 votes

 

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. 

Answer:

Related questions

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