byte order and network byte order

Source: Internet
Author: User
1-byte sequenceBecause different computer systems use different byte sequences to store data, the same 4-byte 32-bit integer is stored in memory in a different way. The byte order is divided into small tail byte sequence (Little endian) and large tail byte sequence (big endian), most of the Intel processor uses the small tail byte sequence, the Motorola processor most uses the big tail (large endian) byte order; Small tail is the low byte emissions at the lower end of memory, high byte emissions in the high-end memory. For example, a 4-byte integer with a value of 0x1234567 corresponds to a high or low byte:
01 23 45 67
Byte3 Byte2 Byte1 Byte0
High byte--à---------à--------------à low byte
will be discharged in memory in the following order:
Memory address serial Number Byte in-memory address 16 in value
0x03 Byte3 01
0x02 Byte2 23
0x01 Byte1 45
0x00 Byte0 67
The big tail is high byte emissions at the low end of memory, low byte emissions in the high-end memory. For example, a 4-byte integer with a value of 0x1234567 corresponds to a high or low byte:
01 23 45 67
Byte3 Byte2 Byte1 Byte0
High byte--à---------à--------------à low byte
will be discharged in memory in the following order:
Memory address serial Number Byte in-memory address 16 in value
0x03 Byte0 67
0x02 Byte1 45
0x01 Byte2 23
0x00 Byte3 01
2 network byte orderThe TCP/IP protocol defines the byte order as a large tail, so the byte order used in the TCP/IP protocol is often called the network byte order. 3 string in-memory storage (Intel series)     strings and integers are the opposite, and the index of the string is stored in memory from low to high; Char s[4] = "ABC";
A B C /0
S[0] S[1] S[2] S[3]
will be discharged in memory in the following order:
Memory address serial Number 16 in value Position of the pointer p
0xbffeadf7 /0 P+3
0xbffeadf6 C P+2
0xbffeadf5 B P+1
0xbffeadf4 A P
int main (void) {char s[4] = "ABC";       char *p = s;      printf ("%02x,%02x,%02x,%02x/n", &s[0], &s[1], &s[2], &s[3]);      printf ("%02x,%02x,%02x,%02x/n", p, p+1, p+2, p+3); printf ("% C,   % C, % C, % C/n ", S[0], s[1], s[2], s[3]); return 0; Output results: [netcool@hfinmsp2 demo]$./demo001 bffeadf4, Bffeadf5, &

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.