谁能帮忙把这段VB代码翻译成 delphi 的 谢谢了(50分)

  • 主题发起人 主题发起人 nosence
  • 开始时间 开始时间
N

nosence

Unregistered / Unconfirmed
GUEST, unregistred user!
Dim HexNum,BoolNum,TempNum,BoolValue,Num<br>Dim S,X,E,ECount,XCount<br><br>//***************************************************************<br>VBSBegin <br>&nbsp; &nbsp; Function FloatType(HexNum)<br>&nbsp; &nbsp; BoolNum="":S=0:X=0:E=0<br>&nbsp; &nbsp; '浮点型转整形<br>&nbsp; &nbsp; '(-1)^s &nbsp;* (1 + x) * 2^(e - 127)<br>&nbsp; &nbsp; '得到他的S的值,并转换为正数<br>&nbsp; &nbsp; If HexNum&lt;0 then<br>&nbsp; &nbsp; BoolValue=1:HexNum=2147483648+HexNum<br>&nbsp; &nbsp; Else<br>&nbsp; &nbsp; BoolValue=0<br>&nbsp; &nbsp; End If<br>&nbsp; &nbsp; '将内存里读出的浮点数的十进制表达值转换成二进制<br>&nbsp; &nbsp; While HexNum&gt;=1<br>&nbsp; &nbsp; TempNum=HexNum Mod 2<br>&nbsp; &nbsp; HexNum=HexNum/2<br>&nbsp; &nbsp; BoolNum=TempNum&amp;BoolNum<br>&nbsp; &nbsp; Wend<br>&nbsp; &nbsp; '将得到的二进制补为32位<br>&nbsp; &nbsp; BoolNum=BoolValue&amp;Right("0000000000000000000000000000000000"&amp;(HexNum Mod 2)&amp;BoolNum,31)<br>&nbsp; &nbsp; S=Left(BoolNum,1)<br>&nbsp; &nbsp; TempE=Mid(BoolNum,2,8)<br>&nbsp; &nbsp; TempX=Right(BoolNum,23)<br>&nbsp; &nbsp; '得到E的十进制值<br>&nbsp; &nbsp; ECount=8<br>&nbsp; &nbsp; While ECount&gt;0<br>&nbsp; &nbsp; E1=Mid(TempE,8-ECount+1,1)<br>&nbsp; &nbsp; E=E+E1*2^(ECount-1)<br>&nbsp; &nbsp; ECount=ECount-1<br>&nbsp; &nbsp; Wend<br>&nbsp; &nbsp; '得到X的十进制值<br>&nbsp; &nbsp; XCount=1<br>&nbsp; &nbsp; While XCount&lt;24<br>&nbsp; &nbsp; X1=Mid(TempX,XCount,1)<br>&nbsp; &nbsp; X=X+X1*2^((-1)*XCount)<br>&nbsp; &nbsp; XCount=XCount+1<br>&nbsp; &nbsp; Wend<br>&nbsp; &nbsp; '得到浮点数的十进制值<br>&nbsp; &nbsp; Num=(-1)^S*(1+X)*2^(E-127)<br>&nbsp; &nbsp; FloatType=Round(Num,2)<br>&nbsp; &nbsp; End Function<br>VBSEnd<br><br><br><br><br>//*****************************************************************<br>//***********************例子**************************************<br>dim a<br>vbscall ReadMemory(&amp;H001D27EA,2,a)<br>b=FloatType(a)<br>messagebox(b)
 
后退
顶部