Thursday 19 October 2017

linux - Interpretation of the bytes stored in the memory of Little Endian machine?

In my program i am storing value 512 in int type.


#include 
int main()
{
unsigned int i = 512 ;
char *c = (char*)&i;
printf("c:%u %d\n",c,*c);
printf("c:%u %d\n",c+1,*(c+1));
printf("c:%u %d\n",c+2,*(c+2));
printf("c:%u %d\n",c+3,*(c+3));
}

o/p>


c:3493911684 0
c:3493911685 2
c:3493911686 0
c:3493911687 0

Explanation:512=1000000000 => 00000010 0000000=>02 00.ie 00 00 02 00.so here MSB and LSB =00.In a LE machine LSB should be placed in lowest memory.Hence possible out put for above program should be 00,02,00,00 and which is what i got as an output too.But while interpreting how is it exactly making 512.does it do any calculation in registers.Can any body give some input to this ?


2nd question is does transmition of the bytes in the network is independent of the endianess of the machine or does transmission too take the same ordering as storing ?say for example in LE for storing we follow (LSB first ,then MSB ) so for transmitting too does it follow LSB byte 1st and then MSB.

No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...