Sign up ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

#include <stdio.h>
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));


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

Explanation:512=1000000000 => 00000010 0000000=>02 00 00 02 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.

share|improve this question

migrated from Aug 8 '13 at 16:44

This question came from our site for system and network administrators.

1) I don't understand why you care about this - at all, 2) this would vary wildly based on a huge number of factors such as processor, server architecture, interfaces used, OS etc., 3) it would have little or no impact on performance either way and 4) I STILL don't know what you would care? – Chopper3 Aug 8 '13 at 10:10
@Chopper3>I was thinking that if say bytes are received in the order 00 02 00 00,then in a LE machine its stored as 00 00 02 00 and if its received like 00 00 02 00 ,in LE machine ,its stored as 00 02 00 00.So the way bytes will be stored in machine depends on the order in which it is received.This is my understanding.i feel it is wrong after seeing your post.correct me pls. – Subi Puthalath Aug 8 '13 at 16:28
@EEAA >Its not an off topic.Every piece of doubt is a new step to learning.What i was asking is once the data is stored ,how is it intepreted correctly during reading from a LE machine because in LE MSB is stored in the highest memory?So how does it happen. – Subi Puthalath Aug 8 '13 at 16:36
The problem here is that this has nothing to do with professional system administration, and thus is not a good fit for Server Fault. You can ask general computer questions on our sister site Super User, and programming questions on Stack Overflow. – Michael Hampton Aug 8 '13 at 16:38
@Chopper3>So for the data to be received ,it should come in some order right.I was talking about that order.This makes sense right? – Subi Puthalath Aug 8 '13 at 16:39

1 Answer 1

The registers in a little-endian machine are going to be by definition little-endian.

Transmission of said bytes over any medium is certainly independent of this. You need to be obeying a protocol that says to put the bytes in a specific order when sending and that any bytes received are in a specific order - the unix sockets API has things like htonl() for example. If they don't come in in the right order you need to flip them around before you work on them.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.