Read IEEE floating point with VB .Net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Faezeh
    New Member
    • Jul 2006
    • 1

    Read IEEE floating point with VB .Net

    I want to read 4 byte with IEEE floating point format and convert to decimal number in vb.net, and need to function for shift bits to left in vb .net.

    32 bit IEEE floating point has this format:

    S EEEEEEEE FFFFFFFFFFFFFFF FFFFFFFF
    0 1 8 9 31
    V=(-1)**S * 2 ** (E-127) * (1.F) where "1.F" is intended to represent the binary number created by prefixing F with an implicit leading 1 and a binary point.


    can some one help me?
    thanks.
  • WonderWareTran
    New Member
    • Oct 2006
    • 1

    #2
    Originally posted by Faezeh
    I want to read 4 byte with IEEE floating point format and convert to decimal number in vb.net, and need to function for shift bits to left in vb .net.

    32 bit IEEE floating point has this format:

    S EEEEEEEE FFFFFFFFFFFFFFF FFFFFFFF
    0 1 8 9 31
    V=(-1)**S * 2 ** (E-127) * (1.F) where "1.F" is intended to represent the binary number created by prefixing F with an implicit leading 1 and a binary point.


    can some one help me?
    thanks.
    I wrote this in VB6, hope it helps

    Function Bin2Float(strin gdata As String) As Double
    Dim i As Integer

    Dim signed_part As String
    Dim exponent_part As String
    Dim floating_part As String

    Dim signed As Integer
    Dim exponent As Integer
    Dim float_digit As Integer

    Dim floating As Double
    Dim float_number As Double
    Dim float_factor As Double

    signed_part = Left$(stringdat a, 1)
    exponent_part = Mid$(stringdata , 2, 8)
    floating_part = Right$(stringda ta, 23)

    signed = Bin2Dec(signed_ part)
    exponent = Bin2Dec(exponen t_part)

    For i = 1 To 23
    float_digit = Bin2Dec(Mid$(fl oating_part, i, 1))
    If float_digit = 1 Then
    floating = float_digit / (2 ^ i)
    float_number = float_number + floating
    End If
    Next
    If exponent > 0 Then
    float_factor = 1 + float_number
    ElseIf exponent = 0 Then
    float_factor = float_number
    End If
    '
    ' Debug.Print signed
    ' Debug.Print exponent
    ' Debug.Print float_factor

    If exponent > 0 And exponent < 255 Then
    Bin2Float = ((-1) ^ signed) * (2 ^ (exponent - 127)) * float_factor
    ElseIf exponent = 0 Then
    Bin2Float = ((-1) ^ signed) * (2 ^ -126) * float_factor
    ElseIf exponent = 255 Then
    Bin2Float = 0
    End If

    End Function


    And this is Bin2Dec

    Function Bin2Dec(stringd ata As String) As Long
    Dim n As Integer
    Dim a As Integer
    Dim x As String
    n = Len(stringdata) - 1
    a = n
    Do While n > -1
    x = Mid$(stringdata , ((a + 1) - n), 1)
    Bin2Dec = IIf((x = "1"), Bin2Dec + (2 ^ (n)), Bin2Dec)
    n = n - 1
    Loop
    End Function

    Comment

    Working...