十六进制单精度浮点数转换成十进制数的代码

来源:百度文库 编辑:神马文学网 时间:2024/05/01 17:30:54
2009-02-11 01:14
在模块文件Hexedit.bas中写入CopyMemory的声明
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
'在窗体文件中写入
Function StrhextoSng(strhex As String) As String
Dim l As Long
Dim f As Single
Dim s As String
l = Val("&H" & strhex)
CopyMemory f, l, 4
s = Format(f, "0.000")
StrhextoSng = s
End Function
VC
CString StrhextoSng(CString mystr)
{
CString strmy;
float value;
sscanf(mystr,"%x",&value);//将CString表示的十六进制字符串转换成十六进制数
return strmy.Format("%f",value);
}