delphi十六进制表示的浮点数转换为十进制浮点数的函数
16进制字符串为:405C7107AD9735B3,
将该16进制表示的浮点数转换成10进制数为:113.766093633332,
求转换程序,
该程序最好和C#中的BitConverter.ToDouble()具有相同效果,
function HexToDouble(cs:string):Double; const hexstr: array [0..15] of string = ('0000','0001','0010','0011', '0100','0101','0110','0111', '1000','1001','1010','1011', '1100','1101','1110','1111'); var s,s2,intstr:string; a,b,i,len:integer; x:double; function BintoInt(binstr:String):Int64; var i:integer; begin Result:=0; len:=Length(binstr); for i:=1 to len do Result:=Result+(1 shl (len-i))*StrToInt(binstr[i]); end; begin s:=''; for i:=Length(cs) downto 1 do s:=hexstr[StrToInt('$'+cs[i])]+s; intstr:=copy(s,2,11); s2:=StringOfChar('0',16-length(intstr))+intstr; a:=BintoInt(s2)-1023; delete(s,1,12); s:='1'+s; b:=BintoInt(copy(s,1,a+1)); s:=copy(s,a+2,length(s)); x:=0; len:=Length(s); for i:=1 to len do if s[i]='1' then x:=x+1/(int64(1) shl i); Result:=b+x; end; procedure TForm1.Button1Click(Sender: TObject); begin showmessage(floattostr(HexToDouble('405C7107AD9735B3'))); end;