470,826 Members | 2,021 Online

# 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...
Jul 17 '05 #1
5 7697
On Sat, 21 Feb 2004 13:58:08 GMT, "Dan E." <fo********@twcny.rr.com>
wrote:
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

N# = Val( "&h" + "FFFF" )
Jul 17 '05 #2
"Dan E." <fo********@twcny.rr.com> wrote in message news:<Qt*******************@twister.nyroc.rr.com>. ..
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

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(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
Jul 17 '05 #3
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" <er*****@nowhere.com> wrote in message
news:40***************@news.btclick.com...
On Sat, 21 Feb 2004 13:58:08 GMT, "Dan E." <fo********@twcny.rr.com>
wrote:
Hi All,

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

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

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

Jul 17 '05 #4

"Bob Butler" <bu*******@earthlink.net> wrote in message
"Dan E." <fo********@twcny.rr.com> wrote in message

news:<Qt*******************@twister.nyroc.rr.com>. ..
Hi All,

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(HexDouble 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
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 = "000000000098C13F"

MsgBox Convert(Source)

End Sub
Jul 17 '05 #5
Thanks Bob, This work.

Dan...

"Bob Butler" <bu*******@earthlink.net> wrote in message
"Dan E." <fo********@twcny.rr.com> wrote in message

news:<Qt*******************@twister.nyroc.rr.com>. ..
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

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" _
(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

Jul 17 '05 #6

### This discussion thread is closed

Replies have been disabled for this discussion.