Little endian big endian

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Geevi
    New Member
    • Jan 2007
    • 13

    Little endian big endian

    Hi to all,

    i want a program to find little endian or big endian processor?

    can u help me plz.....
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    Originally posted by Geevi
    Hi to all,

    i want a program to find little endian or big endian processor?

    can u help me plz.....
    Sure, what do you have so far?

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      Originally posted by Geevi
      i want a program to find little endian or big endian processor?
      Why?

      I have yet to think of a good reason for needing a program like this.

      Comment

      • sicarie
        Recognized Expert Specialist
        • Nov 2006
        • 4677

        #4
        Originally posted by Banfa
        Why?

        I have yet to think of a good reason for needing a program like this.
        There's probably not, but I remember writing a program to tell the difference when I was a sophomore :) (I was on one of those "I need to code something every day to keep up with it" stints. I wish I'd stayed on it...).

        Comment

        • RRick
          Recognized Expert Contributor
          • Feb 2007
          • 463

          #5
          This problem shows up in networks when dealing with different processor architectures. If you're passing around binary info, you have to be very careful how you transmit it over the net. I believe the socket routines htons, etc. deal with this. If you have a homebrew/propriatary protocol you'll have to do this yourself.

          Refer to the following link. The company that was interested in this question was a high powered networking company. http://www.thescripts. com/forum/thread603165.ht ml

          Comment

          • gmu
            New Member
            • Feb 2007
            • 1

            #6
            Hi,
            Incase you are still looking for the answer for little big endian conversion checkout www.compintervi ew.com, there is a solution for this and many such interview question problems :)

            Gmu

            Comment

            • DeMan
              Top Contributor
              • Nov 2006
              • 1799

              #7
              Incedently, I have come across situations where knowing endianness is significant -> some conventions require data to be stored a particular way, irresepective of endianness (eg PVK) -> if someone else (not necessarly using the same endianness) needs to be able to access this information, you need to be sure that the format is correct to the specification.
              Part of me says: if you write this for a specific machine, you know the endianness and can write the program specifically for the purpose, but I can almost see where someone may attempt to write code that will run on either (and thus, in the case of PVK would need to convert to little endian on big endian machines, and do nothing on little endian machines).....

              Comment

              • msnk2020
                New Member
                • Mar 2007
                • 1

                #8
                Hi ,


                I want to know how to find the little-endian and big-endian of the processor by using C programming lanaguage. If any one experts of this area or known plz tell me how to do that.

                and also programming explanation means goods, example programs.

                Because it is asked in one interview question for me, please help me.

                i am awaiting your reply.

                Comment

                • DeMan
                  Top Contributor
                  • Nov 2006
                  • 1799

                  #9
                  Did you know UNICODE files start with the combination 0xff 0xfe?

                  Comment

                  • Banfa
                    Recognized Expert Expert
                    • Feb 2006
                    • 9067

                    #10
                    Originally posted by DeMan
                    Incedently, I have come across situations where knowing endianness is significant -> some conventions require data to be stored a particular way, irresepective of endianness (eg PVK) -> if someone else (not necessarly using the same endianness) needs to be able to access this information, you need to be sure that the format is correct to the specification.
                    Part of me says: if you write this for a specific machine, you know the endianness and can write the program specifically for the purpose, but I can almost see where someone may attempt to write code that will run on either (and thus, in the case of PVK would need to convert to little endian on big endian machines, and do nothing on little endian machines).....
                    This is true, I have worked on satellite receivers that had a number of different processors with different endians but the DVB/MPEG2 specification specifies the byte order for the data received.

                    However you do not need to work out which endian the processor has, you just have to write you code so that the endian of the processor is irrelivent to the operation of the code. This isn't that hard to do.

                    For instance you have a buffer with 2 bytes in it which form a short value big with the data in the buffer stored endian.

                    Code:
                    unsigned char DataBuffer[2];
                    unsigned short value;
                    
                    // code to fill in DataBuffer from some source
                    
                    value = (((unsigned short)DataBuffer[0]<<8) | (unsigned short)DataBuffer[1]);
                    This will work regardless of the endian of the processor it is run on.

                    Comment

                    Working...