Verify that STM32 is little-endian storage

Publisher:SereneDreamsLatest update time:2018-09-01 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

I recently wrote an STM32 program and used a union, which caused a question. 
For example, 0x12345678 is stored in a U32 type variable. The big endian and little endian are stored like this.

 Big-endian storage:
       Low address ... High address
       0x   12      34      56      78
Little endian storage:
       Low address ... High address
       0x   78      56     34      121234567

See the code 
`#include "stm32f10x.h"

struct s 

u32 a; 
u8 b; 
};

union B 

u8 c[5]; 
struct s s_1; 
};

union B BB;

int main(void) 

BB.s_1.a=0x12345678; 
BB.s_1.b=0x09; 
while(1); 
}`

Output: 
result

It can be seen that the storage format is little-endian. 
Be sure to pay attention when writing code in the future.


Keywords:STM32 Reference address:Verify that STM32 is little-endian storage

Previous article:STM32 error, error status and solution
Next article:STM32 uses SWD to connect and report errors

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号