473,394 Members | 1,706 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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 7818
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
news:fa*************************@posting.google.co m...
"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
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 = "000000000098C13F"

MsgBox Convert(Source)

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

Dan...

"Bob Butler" <bu*******@earthlink.net> wrote in message
news:fa*************************@posting.google.co m...
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Gaurav Verma | last post by:
Hi, I want to convert a floating point number (or a decimal number say 123.456) into binary notation using a C program. Can somebody help me out with it? Thanks Gaurav --...
9
by: Steven D'Aprano | last post by:
I'm looking for some way to get the next floating point number after any particular float. (Any mathematicians out there: I am aware that there is no "next real number". But floats are not real...
8
by: vendredi5h | last post by:
Hello all, I'd like to split a 64-bits word (hold as a floating point number) into two 32-bits words (hold as integers). Bitwise operators are working on Integers, not on floating point. ...
2
by: laila | last post by:
Hello, I'm a newbie at C and i have a problem:) I tried to solve this by using for. but i couldnt. the program should read a floating point number from the user character by character until the...
14
by: mathieu | last post by:
hi there, I do not understand the syntax for ios_base::precision. Let say I have a floating point: const float f = 0.313244462; How do I write is to a stream ? const float f =...
2
by: avais | last post by:
I am transmitting a numer over a uart and reading the number in Matlab by using fread function. To transmit a number that occupies more than byte. I use and operation to access the individual bytes...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.