MSB and LSB (RPM)

Source: Internet
Author: User

Most significant bit, last (Least) significant bit

Most significant bit (MSB)
Refers to the bit of the highest value in binary. In 16-bit digital audio, its 1th bit has the greatest effect on the number of characters in 16bit. For example, in the decimal 15,389 figure, the number that corresponds to the 1 rows (1) of the million number will have the greatest effect on the value. Compares the "least significant bit" (LSB) to the opposite.
MSB high Leading, LSB low preamble.

When it comes to the problem of byte order, it is bound to involve two CPU factions. That's Motorola's PowerPC series CPU and Intel's x86 series CPUs. The PowerPC series uses big endian to store data, while the x86 series uses little endian to store data. So what is big endian, what is little endian?

In fact, big Endian refers to the low address holds the highest effective byte (MSB), while the little endian is the low address holds the lowest effective byte (LSB).

The text description may be more abstract, the following is illustrated with an image. For example, the order in which the digital 0x12345678 is stored in two different byte-order CPUs is as follows:

Big Endian

Low address High address


----------------------------------------->
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      12 |     34 |     56 | 78 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Little Endian

Low address High address


----------------------------------------->
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|      78 |     56 |     34 | 12 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

As can be seen from the above two figure, the use of big endian way to store data is in line with our human thinking habits. And Little Endian,[email protected]#$%^&*, go to Hell-_-| | |

Why pay attention to the problem of byte order? You might ask. Of course, if you write a program that only runs under a stand-alone environment and doesn't deal with other people's programs, you can completely ignore the existence of the byte-order. But what if your program has to interact with other people's programs? Here I would like to speak two languages. In a program written in the C + + language, the data is stored in a sequence that is related to the CPU on which the platform is compiled, and the program written by J***a only uses the big endian to store the data. Imagine what would happen if you wrote a program written under the x86 platform in the C + + language that would interoperate with someone else's j***a program? Take the above 0x12345678, your program passed to someone else's data, will point to the 0x12345678 pointer to the J***A program, because J***a take the big endian way to store data, it is natural that it will translate your data into 0x78563412. What the? Turned into another number? Yes, that's the result. Therefore, it is necessary to convert the byte sequence before your C program is passed to the J***A program.

Coincidentally, all network protocols are also used in the big endian way to transfer data. So sometimes we also call the big endian way the network byte order. When two hosts communicate in different byte order, they must be converted into the network byte order before transmitting the data. The following four conversion byte-order macros are available in ANSI C.


· Be and Le article completion

I discussed the problem of byte order in the article "Big Endian and Little Endian" on August 9, with the hyperlinks above. But a friend would still ask, if the CPU stores one byte of data, does the order of 8 bits in its bytes also have big endian and little endian? Or is there a difference in the order of the bits?

In fact, this bit sequence is also present. The figure 0xb4 (10110100) is illustrated below.

Big Endian

MSB LSB


---------------------------------------------->
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   1 |   0 |   1 |   1 |   0 |   1 |   0 | 0 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Little Endian

LSB MSB


---------------------------------------------->
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   0 |   0 |   1 |   0 |   1 |   1 |   0 | 1 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

In fact, because the minimum unit of CPU storage data operation is a byte, its internal bit order is what is a black box for our program. That is, you give me a pointer to 0xb4 this number, for the big endian way of the CPU, it is from left to right read this number of 8 bits, and for little endian way of the CPU, is the opposite, is from right to left to read the number of 8 bits. And our program through this pointer access to the number is 0XB4, byte internal bit sequence is not visible to the program, in fact, this is the same as the byte sequence on a single machine.

Then someone might ask, what if it's a network transmission? Will there be a problem? Do you want to convert the bit order by what function? Well, that's a good question. Assuming that the CPU of the little endian mode is passed to the big endian mode CPU one byte, it will read the 8-bit number locally before transmission, and then transmit the 8 bits in the order of the network byte order, so that there will be no problem at the receiving end. And if you want to transmit a number of 32 bits, because this number in the Littel endian side storage accounted for 4 bytes, and the network transmission is in bytes, little endian side of the CPU read out the first word after sending, actually this byte is the original number of LSB, The receiver becomes the MSB and the confusion occurs.

MSB and LSB (RPM)

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.