vb和vc++中将字符串表示的16进制单精度浮点数转换成十进制数的代码

VB
在模块文件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);
}

原来都是超级简单,唉,看来还是要多加强基本功呀

猜你喜欢

转载自blog.csdn.net/ursamjnor/article/details/297986