Loading ...
Sorry, an error occurred while loading the content.

Re: [blug-prog] little endian big endian problem with a structure who has union

Expand Messages
  • Sanandan (Sanandan) Sharma
    ... Hi Simon, 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
    Message 1 of 2 , May 21, 2007
    • 0 Attachment
      On 5/19/07, Simon fgc <simon.fgc@...> wrote:
      >
      > Hello,
      > 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"
      Hi Simon,

      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;
      packet mypacket;
      pStore = &mypacket.length;
      *pStore = 10;
      pStore= &mypacket.value
      *pStore = 1;
      pStore= &mypacket.id
      *pStore = 227;
      pStore++;
      *pStore = 4;
      /* this puts 1251 in mypacket.id in little endian */

      Regards,
      Sanandan
    Your message has been successfully submitted and would be delivered to recipients shortly.