Results 1 to 5 of 5

Thread: Inverse function for Hex()

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Location
    Atlanta, GA
    Posts
    75
    Can anyone tell me if there is an inverse function to the Hex() function (one that converts hexadecimal back to decimal. Thanks.


    Jay D Zimmerman

  2. #2
    Fanatic Member
    Join Date
    Mar 2000
    Location
    That posh bit of England known as Buckinghamshire
    Posts
    658

    Thumbs up Give this a whirl

    Just use &H?, where ? is the hexadecimal number.

    Code:
    MsgBox &H100
    'displays 256
    [Edited by Iain17 on 05-23-2000 at 04:46 PM]
    Iain, thats with an i by the way!

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 1999
    Location
    Atlanta, GA
    Posts
    75
    How can I use this function in coordination with a variable?

  4. #4
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    'Theres probably only one way strings containing hex can be converted to decimal
    Code:
    Function unhex(hex)
        a = Left(hex, 1)
        If a >= "A" Then a = Asc(a) - 55
        B = Right(hex, 1)
        If B >= "A" Then B = Asc(B) - 55
        unhex = Chr(a * 16 + B)
    End Function
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  5. #5
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    it's easier than that... just do this since we know a HEX result is a string

    Code:
      
      '' assumes HEX value has no id prefex ie 0x or &H
      Public Function HEX2DEC(ByRef hex_str As String) as Long
        
        HEX2DEC = CLng("&H" & hex_str)
        
      End Function
    -Shickadance

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