Results 1 to 8 of 8

Thread: [RESOLVED] How do I convert hexadecimal to decimal with double precision (64 bit)

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    5

    Resolved [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

  2. #2
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    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:
    1. [font=Courier New]Option Explicit
    2.  
    3. Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" ( _
    4.     Destination As Any, _
    5.     Source As Any, _
    6.     ByVal Length As Long _
    7. )
    8.  
    9. Private Function DoubleToHEX(dnumber As Double) As String
    10. Dim HexBytes(0 To 7) As Byte
    11. Dim i As Integer
    12. Dim x As String
    13.     CopyMemory HexBytes(0), dnumber, 8
    14.     x = ""
    15.     For i = 0 To 7
    16.         x = HEX00(HexBytes(i)) & x
    17.     Next i
    18.  
    19.     DoubleToHEX = x
    20.  
    21. End Function
    22.  
    23. Private Function HEX00(bNumber As Byte) As String
    24. Dim x As String
    25.     x = "0" & Hex(bNumber)
    26.     HEX00 = Right(x, 2)
    27. End Function
    28.  
    29. Private Function HEXtoDouble(hNumber As String) As Double
    30. Dim HexBytes(0 To 7) As Byte
    31. Dim i As Integer
    32. Dim x As String
    33.     If Len(hNumber) < 16 Then
    34.         MsgBox "Hex Value too big"
    35.         Exit Function
    36.     End If
    37.  
    38.     For i = 0 To 7
    39.         HexBytes(i) = Val("&H" & Mid(hNumber, (8 - i) * 2 - 1, 2))
    40.     Next i
    41.  
    42.     CopyMemory HEXtoDouble, HexBytes(0), 8
    43.  
    44. End Function[/font]
    To use these functions call like so
    VB Code:
    1. [font=courier new]Private Sub Command1_Click()
    2.  
    3. Dim dnumber As Double
    4. Dim hNumber As String
    5. Dim i As Integer
    6.  
    7. 'convert hex to dbl
    8.     'pad with zeros
    9.     hNumber = Text1
    10.     For i = Len(Text1) + 1 To 16
    11.         hNumber = "0" & hNumber
    12.     Next i
    13.     dnumber = HEXtoDouble(hNumber)
    14.     Label1 = dnumber
    15.  
    16. 'convert dbl to hex
    17.     Label2 = DoubleToHEX(dnumber)
    18. [/font]

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2005
    Posts
    5

    Thumbs up 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.

  4. #4
    New Member
    Join Date
    May 2012
    Posts
    6

    Re: [RESOLVED] How do I convert hexadecimal to decimal with double precision (64 bit)

    More simple:

    DecNumber& = CLng("&H" & HexNumber$)

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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???

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6
    New Member
    Join Date
    May 2012
    Posts
    6

    Re: [RESOLVED] How do I convert hexadecimal to decimal with double precision (64 bit)

    Quote Originally Posted by szlamany View Post
    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.

  7. #7
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    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.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  8. #8
    New Member
    Join Date
    May 2012
    Posts
    6

    Re: [RESOLVED] How do I convert hexadecimal to decimal with double precision (64 bit)

    Quote Originally Posted by szlamany View Post
    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
  •  



Click Here to Expand Forum to Full Width