Loading... ## IEE754算法 <div class="panel panel-default collapse-panel box-shadow-wrap-lg"><div class="panel-heading panel-collapse" data-toggle="collapse" data-target="#collapse-4b05247b82878039abce506a789fc78a10" aria-expanded="true"><div class="accordion-toggle"><span>代码如下 点击展开</span> <i class="pull-right fontello icon-fw fontello-angle-right"></i> </div> </div> <div class="panel-body collapse-panel-body"> <div id="collapse-4b05247b82878039abce506a789fc78a10" class="collapse collapse-content"><p></p> ```iecst FUNCTION_BLOCK FB_BinaryFloat VAR_INPUT xEnb:BOOL; (*使能信号*) arTransmit:ARRAY[0..49]OF BYTE; (*需要转化的数组*) END_VAR VAR_OUTPUT xTransmit:BOOL; (*转换开始标志位*) rTransformation:REAL; (*转换结果*) END_VAR VAR arTransmit_MID:ARRAY[1..4] OF BYTE; (*浮点数二进制转换中间变量*) diSign:DINT; (*符号位*) diExponent:DINT; (*指数位*) diMantissa:DINT; (*尾数位*) END_VAR ``` <p></p></div></div></div> <div class="panel panel-default collapse-panel box-shadow-wrap-lg"><div class="panel-heading panel-collapse" data-toggle="collapse" data-target="#collapse-1cda7fdd59f1e60d8c8d36932904a3fe11" aria-expanded="true"><div class="accordion-toggle"><span>代码如下 点击展开</span> <i class="pull-right fontello icon-fw fontello-angle-right"></i> </div> </div> <div class="panel-body collapse-panel-body"> <div id="collapse-1cda7fdd59f1e60d8c8d36932904a3fe11" class="collapse collapse-content"><p></p> ```iecst IF xEnb THEN xTransmit:=TRUE; arTransmit_MID[1]:=arTransmit[3]; arTransmit_MID[2]:=arTransmit[4]; arTransmit_MID[3]:=arTransmit[5]; arTransmit_MID[4]:=arTransmit[6]; ELSE xTransmit:=FALSE; END_IF IF NOT xEnb THEN SysMemSet(ADR( rTransformation),0,SIZEOF( rTransformation)); SysMemSet(ADR( arTransmit_MID),0,SIZEOF( arTransmit_MID)); RETURN; END_IF diSign:=BOOL_TO_DINT(arTransmit_MID[3].7); diExponent:=(arTransmit_MID[3]- BOOL_TO_DINT(arTransmit_MID[3].7)*128)*2+BOOL_TO_DINT( arTransmit_MID[4].7); diMantissa:=( arTransmit_MID[4]-BOOL_TO_DINT( arTransmit_MID[4].7)*128)*256*256+ arTransmit_MID[1]*256+ arTransmit_MID[2]; IF diExponent<>0 AND diExponent<>255 THEN rTransformation:= (EXPT(-1, diSign))*(EXPT(2, diExponent-127))*(1+EXPT(2,-1)* BOOL_TO_DINT(diMantissa.22)+EXPT(2,-2)* BOOL_TO_DINT(diMantissa.21) +EXPT(2,-3)* BOOL_TO_DINT(diMantissa.20)+EXPT(2,-4)* BOOL_TO_DINT(diMantissa.19)+EXPT(2,-5)* BOOL_TO_DINT(diMantissa.18) +EXPT(2,-6)* BOOL_TO_DINT(diMantissa.17)+EXPT(2,-7)* BOOL_TO_DINT(diMantissa.16)+EXPT(2,-8)* BOOL_TO_DINT(diMantissa.15) +EXPT(2,-9)* BOOL_TO_DINT(diMantissa.14)+EXPT(2,-10)* BOOL_TO_DINT(diMantissa.13)+EXPT(2,-11)* BOOL_TO_DINT(diMantissa.12) +EXPT(2,-12)* BOOL_TO_DINT(diMantissa.11)+EXPT(2,-13)* BOOL_TO_DINT(diMantissa.10)+EXPT(2,-14)* BOOL_TO_DINT(diMantissa.9) +EXPT(2,-15)* BOOL_TO_DINT(diMantissa.8)+EXPT(2,-16)* BOOL_TO_DINT(diMantissa.7)+EXPT(2,-17)* BOOL_TO_DINT(diMantissa.6) +EXPT(2,-18)* BOOL_TO_DINT(diMantissa.5)+EXPT(2,-19)* BOOL_TO_DINT(diMantissa.4)+EXPT(2,-20)* BOOL_TO_DINT(diMantissa.3) +EXPT(2,-21)* BOOL_TO_DINT(diMantissa.2)+EXPT(2,-22)* BOOL_TO_DINT(diMantissa.1)+EXPT(2,-23)* BOOL_TO_DINT(diMantissa.0) ); END_IF ``` <p></p></div></div></div> 最后修改:2023 年 06 月 18 日 © 允许规范转载 赞 6 如果觉得我的文章对你有用,请随意赞赏
此处评论已关闭