-
Aug 9th, 2005, 01:51 PM
#1
Thread Starter
New Member
[RESOLVED] How do I convert hexadecimal to decimal with double precision (64 bit)
I want to convert a hex value to a decimal value with double precision. For example: 3FF0000000000000 would convert to: 99.000000000000000
I found this webpage that does the conversion. http://babbage.cs.qc.edu/courses/cs3...-754hex64.html
How would I code a function to do this in VB6?
Thanks.
Last edited by bugaboosun; Aug 9th, 2005 at 02:52 PM.
Reason: Clarification 2
-
Aug 9th, 2005, 05:19 PM
#2
Re: How do I convert hexadecimal to decimal with double precision (64 bit)
Why you would want to do this I can't Imagine, but here it is anyway.
VB Code:
[font=Courier New]Option Explicit
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
Destination As Any, _
Source As Any, _
ByVal Length As Long _
)
Private Function DoubleToHEX(dnumber As Double) As String
Dim HexBytes(0 To 7) As Byte
Dim i As Integer
Dim x As String
CopyMemory HexBytes(0), dnumber, 8
x = ""
For i = 0 To 7
x = HEX00(HexBytes(i)) & x
Next i
DoubleToHEX = x
End Function
Private Function HEX00(bNumber As Byte) As String
Dim x As String
x = "0" & Hex(bNumber)
HEX00 = Right(x, 2)
End Function
Private Function HEXtoDouble(hNumber As String) As Double
Dim HexBytes(0 To 7) As Byte
Dim i As Integer
Dim x As String
If Len(hNumber) < 16 Then
MsgBox "Hex Value too big"
Exit Function
End If
For i = 0 To 7
HexBytes(i) = Val("&H" & Mid(hNumber, (8 - i) * 2 - 1, 2))
Next i
CopyMemory HEXtoDouble, HexBytes(0), 8
End Function[/font]
To use these functions call like so
VB Code:
[font=courier new]Private Sub Command1_Click()
Dim dnumber As Double
Dim hNumber As String
Dim i As Integer
'convert hex to dbl
'pad with zeros
hNumber = Text1
For i = Len(Text1) + 1 To 16
hNumber = "0" & hNumber
Next i
dnumber = HEXtoDouble(hNumber)
Label1 = dnumber
'convert dbl to hex
Label2 = DoubleToHEX(dnumber)
[/font]
-
Aug 10th, 2005, 10:27 AM
#3
Thread Starter
New Member
Re: How do I convert hexadecimal to decimal with double precision (64 bit)
Thanks, moeur.
Your code works. I was going to try to translate the Javascript in that webpage today. That would have taken me quite a while.
The reason for the question was that I do some maintenance on a system that is written in language called Argo Bankpro. The available programing tools are extremely primative.
I am witing a tool in VB to read output from one of their database utilities that dumps C-Tree DB data as text. The output is difficult to read because the numbers are stored in IEEE format and output as hexadecimal.
Thanks again, your help is much appreciated.
-
May 6th, 2012, 03:18 PM
#4
New Member
Re: [RESOLVED] How do I convert hexadecimal to decimal with double precision (64 bit)
More simple:
DecNumber& = CLng("&H" & HexNumber$)
-
May 6th, 2012, 05:43 PM
#5
Re: [RESOLVED] How do I convert hexadecimal to decimal with double precision (64 bit)
Welcome to the forum!
Why are you replying to threads that are years old???
-
May 6th, 2012, 06:37 PM
#6
New Member
Re: [RESOLVED] How do I convert hexadecimal to decimal with double precision (64 bit)
Originally Posted by szlamany
Welcome to the forum!
Why are you replying to threads that are years old???
Because I search for this code and lost time, the two threads I answer are old but first in the search of google for this conversion, and for other people not lost time, the last instruction is the best, I test various, and this is simple, fast and totally operative...
Is the reason, for people that search this conversion, have fast and simple and good solution...
Sorry for my bad English...
Pd: Many persons use VB6, is old, but very usseful, I for example have a program in virtual machine - in a oracle sun virtualbox portable - that I sell, and in the virtual machine have a Windows XP 32 bits, and for this operative system, vb6 is fast and a good solution... And in the virtual machine my program run without changes, worked for decades is possible, and I not lost time in the changes of different versions of windows and changes and craps of microsoft...
Also in virtualbox machine is possible for my sell the program for mac and for linux, good solution without need to create 3 programs... One for each system...
One of the big problems of the programation is that is impossible arrive to a be master master master because each little time, changes, changes, changes, and the programmer need to create a good software of any thing, not lost your time in known new codes all the time...
I with the solution of virtualbox portable, is possible for me put all my time in make a better program, not lose all my time in known the stupids and always changes of microsoft...
Last edited by Javier Reinoso; May 6th, 2012 at 06:46 PM.
-
May 6th, 2012, 06:41 PM
#7
Re: [RESOLVED] How do I convert hexadecimal to decimal with double precision (64 bit)
Good answer - making the thread more meaningful is always a good thing.
-
May 6th, 2012, 06:47 PM
#8
New Member
Re: [RESOLVED] How do I convert hexadecimal to decimal with double precision (64 bit)
Originally Posted by szlamany
Good answer - making the thread more meaningful is always a good thing.
Thanks szlamany!!! Good day!!! Best regards...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|