1. Concept and detailed explanation
There are two main byte storage mechanisms commonly used in computers of various systems: big-endian and little-endian, that is, big-endian mode and little-endian mode.
Let's review two key words first, MSB and LSB:
MSB:Most Significant Bit ------- Most Significant Bit
Big-endian
big-endian: The MSB is stored at the lowest address.
For example, the double-byte number 0x1234 is stored in big-endian format at the starting address 0x00002000:
| data |<-- address
In Big-Endian, the serial number in the bit sequence is arranged as follows (taking the double-byte number 0x8B8A as an example):
bit | 0 1 2 3 4 5 6 7 | 8 9 10 11 12 13 14 15
Little-endian
Little-endian: The LSB is stored at the lowest address.
For example, the double-byte number 0x1234 is stored in little-endian format at the starting address 0x00002000:
| data |<-- address
In Little-Endian, the serial number arrangement in the bit sequence is exactly the opposite of Big-Endian, as follows (taking the double-byte number 0x8B8A as an example):
bit | 15 14 13 12 11 10 9 8 | 7 6 5 4 3 2 1 0
2. Storage of arrays in big-endian and small-endian situations:
Take unsigned int value = 0x12345678 as an example, and look at its storage in two byte orders. We can use unsigned char buf[4] to represent value:
Big-Endian: The high bits are stored in the low addresses, as follows:
High address
Little-Endian: The low address stores the low bits, as follows:
High address
3. Big-endian and small-endian conversion method:
Big-Endian is converted to Little-Endian as follows:
#define BigtoLittle16(A)
4. Big-endian and small-endian detection methods:
How to check if processor is big-endian or little-endian?
The storage order of the union is that all members are stored starting from the lowest address. This feature can be used to easily obtain whether the CPU uses Little-endian or Big-endian mode to read and write memory .
int checkCPUendian()
Previous article:Three-phase AC voltage regulation control system for electrostatic precipitator power supply based on single-chip microcomputer 80C196KC
Next article:Implementation of multi-waveform radar signal generator based on AD9957
Recommended ReadingLatest update time:2024-11-17 00:00
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- About fatalerror in Modelsim simulation
- Several concepts about switching power supply
- Review summary: Shanghai Hangxin ACM32F070 development board + touch function evaluation board
- Register Control of LMX2592
- [Fudan Micro FM33LG0 Series Development Board Review] LCD Usage and Truth Table Tool Instructions
- Renesas CPK-RA6M4 development board evaluation + ISL29035 light sensor reading data
- I am looking for a detailed and detailed literature or article on the theoretical explanation of parallel communication between 51 microcontroller and FPGA.
- The signal strength of the mobile phone is -109dbm, 31asu--- Why is dBm a negative value? -100dbm and -120dbm, which signal is stronger?
- The east-west direction of the compass is reversed
- Looking for a serial port assistant that can send commands alternately and supports 2400 baud rate