MIPS big-endian and little-endian issues

 This article is reproduced from the link: https://blog.csdn.net/Z_hehe/article/details/53310157

       Sure enough, after the last transplant Libjpeg to problems openWRT, new problems have emerged, before you write with RTP transport jpg images to the VLC program, no problem running on a virtual machine, but the cross-compiler to develop when the board to die, image data is transmitted out, but VLC is not receiving end image. Finally, the packet capture tool capture looked only to find, grab bag is a mess ah, RTP UDP header data in the back of the head completely messed up. Ethereal also caught the TCP three-way handshake (do not understand why), and what was it, what kind of encryption (that is encrypted, only to discover later want more).

        No way, start looking for questions from the program ah, finally found the problem is probably byte order. Sure enough, the written backwards RTP header defined with positive write head is set to receive the correct transmission of the RTP packet capture, image can be displayed in VLC.

        Later went online around the shop, only to find, as most of the MIPS and network byte order, as a big-endian mode, and I usually in ubuntu virtual machine and arm development board are little-endian mode, which would be a endian conversion functions (htonl, htons,), but the big endian mode in the MIPS would not, so the program in the endian conversion functions on the list are also removed.

Incidentally review under the big-endian and little-endian it:

       Byte order, also called endian, endian, English: Endianness.
       In the field of computer science, endian order refers to a byte data storing multiple bytes (byte), the typical case is the transmission order storage network transmission mode and an integer in memory. Endianness sometimes also use pointing sequence (bit).


      Size endian architecture with hardware-related, all x86 series of pc machines are little-endian, nothing to do with the operating system. Solaris systems on the x86 family of pc is little-endian, solaris sun sparc platform is big-endian.

      Big endian, the high byte stored in low memory address low byte stored in high address memory; little endian and vice versa.

     As a long type 0x12345678
       big-endian:
           lower memory address -> 0x12
                                  0x34
                  0x56
          high memory address -> 0x78

      little endian:
          lower memory address -> 0x78      
               0x56
               0x34
          high memory address -> 0x12

 

  However, when the data transmission is transmitted to the transmission of a byte by byte manner, then there is no problem large segment sequence, to the little-endian

 

Analyzing small end CPU program:


Joint (Union) mode determination method

All members of the union in a common space to store the same time only one data member, all members have the same data

The starting address. That is, although the above-described union defines two members, but in fact only the union occupies 4 bytes (32-bit machines), to a member of the

Assignment, then read on the b-phase reading a value of the first byte of a lower member. If the machine is to use big-endian mode, ua = 1 that a maximum value of 1 byte;

If the machine is to use small pieces mode, ua = 1 then a minimum of 1 byte. A and b have the above seen that the same starting position, so read is equal to 1 if b,

Compared to little-endian mode, b is 0 compared to big endian mode.

typedef union {  
    int i;  
    char c;  
}my_union;  
  
int checkSystem1(void)  
{  
    my_union u;  
    u.i = 1;  
    return (u.i == u.c);  
}  

  


----------------
Disclaimer: This article is CSDN blogger "Z_hehe 'original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: https: //blog.csdn.net/z_hehe/article/details/53310157

 

Analyzing two methods to program the size of the end

Disclaimer: This article is a blogger original article, follow the  CC 4.0 BY-SA  copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/kit_9875507/article/details/44264663

Guess you like

Origin www.cnblogs.com/xiaohujian/p/11962413.html