Results 1 to 4 of 4

Thread: Converting an 8 byte decimal to hex

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    4

    Converting an 8 byte decimal to hex

    Does anyone have any ideas on how to convert a 64 bit (20 digit) decimal to hex?

    Problems:

    The built-in Hex() function doesn't work as it only supports up to 32 bits.

    I did write a custom routine to do the conversion, however it relies on setting the "maximum hex value" you want before you do the conversion. The problem here is that there aren't any data types besides a double that support a 64 bit number. And I can't use a double because I need exact accuracy in the digits and not be limited to the floating point standard. So what results is that I get the first 6 or 7 bytes of the number but not the whole thing. I'm not married to this routine, I just need anything that will convert a 20 digit decimal string to an 8 byte hex string.

    Help! I have also submitted this to the general forum if this is the improper place. First post, go easy on me. Thanks

  2. #2
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530

    Sure can

    Take up to 29 digit integer number and converts to hex
    VB Code:
    1. Function DecToHex(ByVal x As Variant) As String
    2.  'Nucleus
    3.  Dim y%: x = CDec(x)
    4.  Do
    5.     y = (x / 16 - Int(x / 16)) * 16
    6.     If y < 10 Then DecToHex = y & DecToHex Else DecToHex = Chr$(y + 55) & DecToHex
    7.     x = Int(x / 16)
    8.  Loop While x
    9. End Function

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2001
    Posts
    4
    genius.

    That works perfectly. You have greatly simplified my life. Thanks

  4. #4
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    Last edited by Nucleus; Aug 16th, 2001 at 06:51 AM.

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