无符号数相减溢出

u16 a=190;

u16 b=1020;

u16 c=0;

c=a-b;

c=0xfcc2;

单片机采用补码运算,需要程序员认为识别是有符号数还是无符号数。通过最高bit判断。


//相差不大取上一次的值

if(Fluor_Value_100x_backup!=Fluor_Value_100x)

{

                //用减法处理会有溢出情况                

if((Fluor_Value_100x_backup>(50+Fluor_Value_100x))||(Fluor_Value_100x>(Fluor_Value_100x_backup+50)))
Fluor_Value_100x_backup=Fluor_Value_100x;
else
Fluor_Value_100x=Fluor_Value_100x_backup;
}


你可能感兴趣的:(C)