2012年3月26日星期一

Beats By Dre SaleSummary:1

Summary:1 ,80X86 uses the small end method ,network byte order using big-endian .2 ,binary network programming ,data transmission ,preferably in unsigned char ,unsigned short ,Beats By Dre Sale,unsigned int unsigned short ,unsigned short ,in network byte order processing after the copy to send buffer 3 ,structure prior to the specified # pragma pack ( 1) pragma pack structure after # ( ) for the byte order ( big endian ,small end method) defined UNXI network programming definition : the term &ldquo ;&rdquo and &ldquo ;the small end ;end &rdquo ;representing multi-byte values which end ( the end ) stored in this value to the starting address .
Small end of initial address ,is little endian ;there is a starting address ,is the big endian .Also can say: 1 small end method ( Little-Endian ) is the low byte in memory address discharge low end is the value to the starting address high byte in memory ,from high address end .
2 big endian ( Big-Endian ) is a high byte in memory address discharge low end is the value to the starting address ,the low-order byte in memory address end discharge .Cite a simple example ,for the plastic 0x12345678 .
It is in big endian and the small end of the system and the method ,respectively, as shown in Figure 1 of the store .We know that the network data stream is a stream of bytes, for more than one byte values ,Men Nike Running Shoes,in the network transmission time, to transfer which byte ?That is to say ,when the receiving end receives the first byte of the time ,it is the byte as high or low to handle ?Network byte order definition :received the first byte is used as a high view ,Beats By Dre Sale,this requires the sender to send the first byte should be high .
While at the sending end sends data, sends the first byte is the figure in the memory start address corresponding to the byte .Visible multiple byte values before sending, in memory of the value should be a method to store .
Network byte order is big endian .For example, we through the network to send 0x12345678 the shaping ,Cheap Vibram,in 80X86 platform ,it is with the small end method for storage, before it is sent to need to use the system to provide the htonl converts it into big-endian deposited ,as shown in figure 2 .
Different CPU platforms byte order usually are not the same ,I wrote a simple C program ,you can test it on different platforms of the byte order .In 80X86CPU platform ,the implementation of the procedures are as follows: :0x78 :0x56 :0x34 :0x12 :0x12 :0x34 :0x56 :0x78 analysis results ,Beats Headphones,in the 80X86 platform ,the system will more bytes the low temperature starting address stored in variables ,using the small end method .
Htonl i_num into the network byte order ,visible network byte order is big endian .# include < ;stdio.h> include < ;# ;netinet / in.h> ;/ * judge whether or not the small end
,is back to 1 ,not to return 0 * / int IsLittleEndian ( ) {unsigned short num = 0x1234 ;if ( ( & * ( char * ) ;Num ) = = 0x34 ) return 1 ;return 0 ;} int main ( ) {unsigned
short i_num = 0x1234 ;if ( IsLittleEndian ( ) ) printf ( little endian / N ) ;else printf ( big endian / N ) ;printf ( :0x%x / N * ( char * ) ,( i_num + & ;0)
) ;printf ( :0x%x / N ,* ( ( char * ) & ;i_num + 1 ) ) ;i_num = htons ( i_num ) ;printf ( n ) ;printf ( :0x%x / N ,* ( char * ( & ) ;i_num + 0 ) ) ;printf
Related articles:

没有评论:

发表评论