in DS
897 views
0 votes
0 votes

Suppose we have an array with base address 2000. Each element of the array occupies 2 bytes. And we want to fetch the first 8 bits of the first element of the array. What will it return?

More precisely I want to know what is stored in memory location 2000 to 2001  are stored in binary in the array?

400 401 402 403 404

 

in DS
897 views

4 Comments

scaling factor of 2 is used i.e for each 2 byte we allot an address.

144 takes 2 bytes, 256 takes 2 bytes, 145 takes 2 bytes and so on.

if int is of 4 bytes then scaling factor of 4 will be used.
0
0
yes because storage and accessing are different things... we store this way in memory but when we will access it it will be 20012000 20032002...........
0
0
I didn't understand.

If 2000 has 144,then 2001 should contain 1.

Some one please elaborate.
0
0

1 Answer

0 votes
0 votes

I have assumed that the processor is using Little Endian mode. For Big Endian processors the memory will be reversed.

400 can be written in binary as 

256 128 64 32 16 8 4 2 1

  1    1    0    0   1 0 0  0 0

So, 2000 to 2001 will contain 10010000

      2001 to 2002 will contain 00000001

     and 2002 to 2003  , and 2003 to 2004 will contain all 0's

In Big Endian  processors , these assignments will be reversed ,i.e , 2000 to 2001 will have all 0's

 

For More examples --->

https://www.quora.com/How-is-an-integer-value-stored-in-the-memory-in-C

 

edited by

2 Comments

in my opinion 2000 to 2001 should contain 10010000
0
0
Yes ,silly mistake, fixed that .
0
0