8-byte floating point number

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dan E.

    8-byte floating point number

    Hi All,

    If I have an 8-byte floating point number in hex how do I convert it to a
    double?

    0 0 0 0 0 98 C1 3F this should be about .13746

    Thanks

    Dan...


  • J French

    #2
    Re: 8-byte floating point number

    On Sat, 21 Feb 2004 13:58:08 GMT, "Dan E." <formulazzz@twc ny.rr.com>
    wrote:
    [color=blue]
    >Hi All,
    >
    >If I have an 8-byte floating point number in hex how do I convert it to a
    >double?
    >
    >0 0 0 0 0 98 C1 3F this should be about .13746[/color]

    N# = Val( "&h" + "FFFF" )


    Comment

    • Bob Butler

      #3
      Re: 8-byte floating point number

      "Dan E." <formulazzz@twc ny.rr.com> wrote in message news:<QtJZb.343 45$um1.10351@tw ister.nyroc.rr. com>...[color=blue]
      > Hi All,
      >
      > If I have an 8-byte floating point number in hex how do I convert it to a
      > double?
      >
      > 0 0 0 0 0 98 C1 3F this should be about .13746[/color]

      Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMem ory" _
      (ByRef d As Any, ByRef s As Any, ByVal nbytes As Long)

      Private Sub Main()
      Dim b(1 To 8) As Byte
      Dim f As Double
      b(1) = 0
      b(2) = 0
      b(3) = 0
      b(4) = 0
      b(5) = 0
      b(6) = &H98
      b(7) = &HC1
      b(8) = &H3F
      CopyMemory f, b(1), 8
      MsgBox f
      End Sub

      ----------------------------

      Private Type bybytes
      b(1 To 8) As Byte
      End Type
      Private Type bydouble
      f As Double
      End Type

      Private Sub Main()
      Dim bdata As bybytes
      Dim fdata As bydouble
      bdata.b(1) = 0
      bdata.b(2) = 0
      bdata.b(3) = 0
      bdata.b(4) = 0
      bdata.b(5) = 0
      bdata.b(6) = &H98
      bdata.b(7) = &HC1
      bdata.b(8) = &H3F
      LSet fdata = bdata
      MsgBox fdata.f
      End Sub

      Comment

      • Dan E.

        #4
        Re: 8-byte floating point number

        Hi

        This did convert the Hex to Dbl. but not what I'm expecting. I think what I
        ned is a way to convert 8 byte, little endian, IEEE format to double. I
        just looked at the 'little endian' format but I can not find anything
        related to VB.

        Has anyone ever deal with this before.

        Thanks.

        Dan....

        "J French" <erewhon@nowher e.com> wrote in message
        news:4037a49a.3 1094526@news.bt click.com...[color=blue]
        > On Sat, 21 Feb 2004 13:58:08 GMT, "Dan E." <formulazzz@twc ny.rr.com>
        > wrote:
        >[color=green]
        > >Hi All,
        > >
        > >If I have an 8-byte floating point number in hex how do I convert it to[/color][/color]
        a[color=blue][color=green]
        > >double?
        > >
        > >0 0 0 0 0 98 C1 3F this should be about .13746[/color]
        >
        > N# = Val( "&h" + "FFFF" )
        >
        >[/color]


        Comment

        • Steve Gerrard

          #5
          Re: 8-byte floating point number


          "Bob Butler" <butlerbob@eart hlink.net> wrote in message
          news:fa10fb0.04 02211430.551dad d0@posting.goog le.com...[color=blue]
          > "Dan E." <formulazzz@twc ny.rr.com> wrote in message[/color]
          news:<QtJZb.343 45$um1.10351@tw ister.nyroc.rr. com>...[color=blue][color=green]
          > > Hi All,
          > >[/color][/color]

          A small elaboration of Bob's nice method:

          Private Type bybytes
          b(0 To 7) As Byte
          End Type
          Private Type bydouble
          f As Double
          End Type

          Private Function Convert(HexDoub le As String) As Double
          Dim bdata As bybytes
          Dim fdata As bydouble
          Dim n As Long

          If Not IsNumeric("&H" & HexDouble) _
          Or Len(HexDouble) <> 16 Then
          MsgBox "Bad dog."
          Else
          For n = 0 To 7
          bdata.b(n) = Val("&H" & Mid$(HexDouble, n * 2 + 1, 2))
          Next n
          LSet fdata = bdata
          Convert = fdata.f
          End If

          End Function

          Private Sub Command1_Click( )
          Const Source As String = "000000000098C1 3F"

          MsgBox Convert(Source)

          End Sub


          Comment

          • Dan E.

            #6
            Re: 8-byte floating point number

            Thanks Bob, This work.

            Dan...

            "Bob Butler" <butlerbob@eart hlink.net> wrote in message
            news:fa10fb0.04 02211430.551dad d0@posting.goog le.com...[color=blue]
            > "Dan E." <formulazzz@twc ny.rr.com> wrote in message[/color]
            news:<QtJZb.343 45$um1.10351@tw ister.nyroc.rr. com>...[color=blue][color=green]
            > > Hi All,
            > >
            > > If I have an 8-byte floating point number in hex how do I convert it to[/color][/color]
            a[color=blue][color=green]
            > > double?
            > >
            > > 0 0 0 0 0 98 C1 3F this should be about .13746[/color]
            >
            > Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMem ory" _
            > (ByRef d As Any, ByRef s As Any, ByVal nbytes As Long)
            >
            > Private Sub Main()
            > Dim b(1 To 8) As Byte
            > Dim f As Double
            > b(1) = 0
            > b(2) = 0
            > b(3) = 0
            > b(4) = 0
            > b(5) = 0
            > b(6) = &H98
            > b(7) = &HC1
            > b(8) = &H3F
            > CopyMemory f, b(1), 8
            > MsgBox f
            > End Sub
            >
            > ----------------------------
            >
            > Private Type bybytes
            > b(1 To 8) As Byte
            > End Type
            > Private Type bydouble
            > f As Double
            > End Type
            >
            > Private Sub Main()
            > Dim bdata As bybytes
            > Dim fdata As bydouble
            > bdata.b(1) = 0
            > bdata.b(2) = 0
            > bdata.b(3) = 0
            > bdata.b(4) = 0
            > bdata.b(5) = 0
            > bdata.b(6) = &H98
            > bdata.b(7) = &HC1
            > bdata.b(8) = &H3F
            > LSet fdata = bdata
            > MsgBox fdata.f
            > End Sub[/color]


            Comment

            Working...