4656 views|11 replies

1643

Posts

0

Resources
The OP
 

I would like to ask, how to assign a uint32 variable to a uint8 variable? [Copy link]

 

邀请:@maychang   @damiaa   @skywalker_lee   @Gen_X   参与回复

The following code

unsigned char c1 ;
unsigned int i1 ;

i1=0x12 34 5678;

i1=i1>>16;

i1=i1 & 0x000000ff;

c1=i1;

I want to assign the values of 3 and 4 in the i1 variable to the variable c1.

Excuse me, is there any error in the final c1=i1?

This post is from MCU

Latest reply

i1 = i1 >> 16; The result is that i1 is 0, and you cannot get the result you want.   Details Published on 2024-2-24 13:08
 

1643

Posts

0

Resources
2
 

Teacher maychang , I clearly replied, why can't I see it, moderator?

This post is from MCU
 
 

79

Posts

0

Resources
3
 

I think your function is implemented numerically.

As for the last question "Is there an error in the final c1=i1?" If it is a program judgment here, then (c1 == i1) = true, and its judgment mechanism is to force the conversion of uint8_t into uint32_t.

This post is from MCU

Comments

grateful.   Details Published on 2022-5-16 08:53
grateful.   Details Published on 2022-5-16 08:52
 
 
 

1643

Posts

0

Resources
4
 
javnson posted on 2022-5-15 21:51 I think your function has been realized numerically. As for the last question "Is there an error in the last c1=i1?" If it is a program...

grateful.

This post is from MCU
 
 
 

1643

Posts

0

Resources
5
 
javnson posted on 2022-5-15 21:51 I think your function has been realized numerically. As for the last question "Is there an error in the last c1=i1?" If it is a program...

I want to ask, if I assign 32-bit data directly to an 8-bit variable, will there be any anomalies?

This post is from MCU

Comments

Won't  Details Published on 2022-5-16 09:57
 
 
 

79

Posts

0

Resources
6
 
Shenzhen Xiaohua published on 2022-5-16 08:53 I want to ask, if 32-bit data is directly assigned to an 8-bit variable, there will be no abnormality, right?

Won't

This post is from MCU
 
 
 

39

Posts

0

Resources
7
 

i1 = i1 >> 16;

c1 = (unsigned char)(i1 & 0xff); // C type conversion, I am used to using (TYPE); In addition c1 = (unsigned char)(i1 & 0xff) = (unsigned char)i1 = i1

This post is from MCU

Comments

Thank you very much. Is it OK to have c1=i1 without enforcing type conversion? I just want to get the lowest byte of i1?  Details Published on 2022-5-16 11:36
 
 
 

1643

Posts

0

Resources
8
 
mingplus posted on 2022-5-16 11:00 i1 = i1 >> 16; c1 = (unsigned char)(i1 & 0xff); // C mandatory class...

Thank you very much. Is it OK to have c1=i1 without enforcing type conversion? I just want to get the lowest byte of i1?

This post is from MCU
 
 
 

1022

Posts

0

Resources
9
 

Correct operation!

no problem!

This post is from MCU
 
Personal signatureچوآن شـين
 
 

1462

Posts

0

Resources
10
 
I am a newbie, I am here to learn. From my limited knowledge, it seems that there is no mistake
This post is from MCU
 
 
 

7422

Posts

2

Resources
11
 

Truncate and find out.

This post is from MCU
 
Personal signature

默认摸鱼,再摸鱼。2022、9、28

 
 

867

Posts

0

Resources
12
 

i1 = i1 >> 16; The result is that i1 is 0, and you cannot get the result you want.

This post is from MCU
 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list