TODO: Some understanding of byte order

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

TODO: Some understanding of byte order


This article is a small part of the byte sequence of the one-sided understanding, I hope you have help ha.

Byte order, that is, when the sequence of bytes stored in the computer and input (output) sequence is the first-to-last or back-to-front.

1. Little Endian: Store low-order bytes at the start address, commonly known as small end

2. Big endian: High-order bytes are stored in the start address, commonly known as the endian

such as a 0x01020304 (left high right low) This integer, under the small end in memory layout is as follows

[04] [03] [02] [01] Note that the left is the low address, and the right is the high address

Under the big-endian, it's

[01] [02] [03] [04] Note that the left side is the high address, while the right side is the low address.

Compared to big-endian, small-end sort, the use of data storage is more in line with human thinking habits.

Because some people on the internet are not the same to the big end, the small side of the understanding; The small series will write a Golang code to demonstrate the correctness of small end, big-endian sort.

Network byte order, refers to the network transmission of the byte sequence, may be big-endian or small-order, depending on the beginning of the software communication between the two sides of the protocol provisions. The TCP/IP protocol RFC1700 The use of the "big-endian" byte sequence as a network byte order, which is required for development.

On the existing platform, Intel's X86 uses Little-endian, and Big-endian, like Sun's SPARC, uses it. In the C language, the default is the small end (in some microcontroller implementation is based on big-endian, such as Keil 51C), Java is platform-independent, the default is the side, Golang is also the default use end. Different languages use different byte sequences, and the transfer of each other needs to be done by byte-order conversion.

Finally, attach the Golang to the size end of the test code


Output:

a:305419896

Bigendian:12 34 56 78

b:305419896

c:305419896

tt:0x12345678

The TT output 0x123456 indicates that go uses the big-endian. If the need for small-end testing as long as the Bigendian to Littleendian can be, interested to try.

Related Article

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.