Understand the big end and small end, and understand the big end

Source: Internet
Author: User

Understand the big end and small end, and understand the big end
I want to teach you how to quickly understand the underlying programming or reverse development of shoes on the big and small ends. Are you sure you are familiar with these two terms ?! Today, we will introduce these two concepts: Big-Endian and Little-Endian! In the computer field, it indicates the order in which data is stored in the memory. different CPUs and operating systems have different data storage methods. However, common operating systems are small terminals, while communication protocols are large ones. But it doesn't mean that the system is a small-end storage, and files must adopt a small-end format. Different applications have different storage methods for their own data, for example: * Adobe PS -- big end * BMP -- small end * GIF -- small end * JPEG -- big end * MacPaint -- big end * RTF -- what is the difference between Small End and big end? For example, 0x12345678: * large-end methods are stored in bytes in the memory: 12 34 56 78 * The Small-end method is stored in byte order in the memory as follows: 78 56 34 12 explanation: Large-end: High valid bytes are stored in a low-end memory address, the lower valid bytes are stored in the higher memory address. For example, if the integer variable 0x12345678 occupies 4 bytes, the memory address is as follows:

Data 0x12 0x34 0x56 0x78
Address Zero x 10000000 Zero x 10000001 Zero x 10000002 Zero x 10000003
Small End: a higher valid byte is stored in a higher storage address, and a lower valid byte is stored in a lower storage address. Therefore, Integer Variables 0x12345678 are stored as follows based on the memory address from small to large:
Data 0x78 0x56 0x34 0x12
Address Zero x 10000000 Zero x 10000001 Zero x 10000002 Zero x 10000003
Conversion: We found that one byte can store two hexadecimal numbers (the maximum number of bytes that can be stored in one byte is 0xFF). If you are given a decimal number (such as 112233 ), how can I quickly know how it is stored in the memory? L The Big-end method is easy to convert directly into a hexadecimal system, and then store it in sequence: 0x0001B669l the small-end method is troublesome. The steps are as follows: * convert to a hexadecimal number (0x0001B669) * swap the four-digit and four-digit characters (0xB6690001). * swap the four-digit and four-digit characters (0x69B60100) in the four-digit and four-digit characters (0x69B60100) how can I check whether your machine is large or small? As mentioned above, most common personal computers use small computers, but we are all programmers who change the world. How can we use code to distinguish them? In fact, it is not difficult to convert int to insert a single byte to determine the actual storage location: # include <stdio. h> int main () {int a = 0x2233; char * B = (char *) & a; if (* B = 0x22) {printf ("big end! \ N ");} else {printf (" Small End! \ N ") ;}return 0 ;}< ignore_js_op>

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.