none
vb.net将32位十六进制浮点数与十进制小数

    问题

  • 请教vb.net中如何将32位十六进制浮点数与十进制小数相互转换的函数。例如,如何将“41C8CCCD"转换成25.10;又如何将25.10转换成"41C8CCCD"
    2016年8月27日 12:25

答案

  • 你好,

    请参考下面的代码

     Dim hexString As String = "41C8CCCD"
            Dim num As UInteger = UInteger.Parse(hexString, System.Globalization.NumberStyles.AllowHexSpecifier)
    
            Dim floatVals As Byte() = BitConverter.GetBytes(num)
            Dim f As Single = BitConverter.ToSingle(floatVals, 0)

    >>又如何将25.10转换成"41C8CCCD

    Dim f As Single = 25.1F
            Dim b As Byte() = BitConverter.GetBytes(f)
            Dim sb As New StringBuilder()
            For Each by As Byte In b
                sb.Append(by.ToString("X"))
            Next
            Console.WriteLine(sb.ToString())

    Best regards,

    Cole Wu


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    2016年8月28日 2:12
    版主