Re: [blug-prog] little endian big endian problem with a structure who has union
- On 5/19/07, Simon fgc <simon.fgc@...> wrote:
> I am using Mips 32 target and i use below structure
> the data passed is
> "00 00 00 10 "
> "00 01"
> "12 51"
> whereas the correct data that i need to pass is
> "10 00 00 00"
> "01 00"
> "51 12"
Obviously you need a little endian representation where as your
machine is big endian.
I am not sure what you are trying to do but it is not a good idea to
have a program which
assumes some internal representation for multibyte data types. If this
is a network packet
you are trying to analyse it is better to have a byte stream to handle it.
But anyway you can overcome your present problem with a dirty hack like this:
char * pStore;
pStore = &mypacket.length;
*pStore = 10;
*pStore = 1;
*pStore = 227;
*pStore = 4;
/* this puts 1251 in mypacket.id in little endian */