芯片大小端验证

大端的高位字节在低地址处,小端的低位字节在低地址处
以 int32_t a = 0x12345678为例
image



看到一段大小端验证代码,记录下来

点击查看代码
uint32_t endianess_test = 0x11223344;
uint8_t * endianess_test_p = (uint8_t *) &endianess_test;
bool big_endian = endianess_test_p[0] == 0x11 ? true : false;
if(big_endian) {
    LV_ASSERT_MSG(LV_BIG_ENDIAN_SYSTEM == 1,
                  "It's a big endian system but LV_BIG_ENDIAN_SYSTEM is not enabled in lv_conf.h");
}
else {
    LV_ASSERT_MSG(LV_BIG_ENDIAN_SYSTEM == 0,
                  "It's a little endian system but LV_BIG_ENDIAN_SYSTEM is enabled in lv_conf.h");
}
posted @ 2024-08-22 16:46  Charles_hui  阅读(31)  评论(0)    收藏  举报