[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 513
  • Last Modified:

Converting HEX values

I am going to extract HEX values from a file that is dumped from EPROM's.
Most of this values are to be extracted as Int or Long.
However, some of this values are to be converted to ASCII characters, and that's stopping me at the moment.
Is there any easy solution ?
0
rus
Asked:
rus
  • 3
  • 2
1 Solution
 
deightonCommented:
Do you mean the Hex values will be in the form of Hex number strings e.g. "1AB2" etc

If so answer to follow
0
 
deightonCommented:
Private Function Hex_to_int(sX As String) As Long

    Dim sAtom As String
    Dim c As Integer
    Dim mFactor As Long
   
    mFactor = 1
   
   
    For c = Len(sX) To 1 Step -1
       
        sAtom = UCase(Mid(sX, c, 1))
       
        If sAtom >= "0" And sAtom <= "9" Then
           
            Hex_to_int = Hex_to_int + Val(sAtom) * mFactor
           
        Else
       
            Hex_to_int = Hex_to_int + (Asc(sAtom) - Asc("A") + 10) * mFactor
           
        End If
       
        mFactor = mFactor * 16
       
    Next
           

End Function


Private Sub Command1_Click()
   
    MsgBox Str(Hex_to_int("abc1"))   'displays 43969
   
End Sub

0
 
rusAuthor Commented:
Yes, The Hex values is like "1AB2" etc.
In VB there is a HEX-function but it returns a string with the hexadecimal value of a number. I would like it the other way,
Hexadecimal to number. In that way I should be able to extract the ascii characters by using the Chr-function.
Don't you think that...
0
 
deightonCommented:
if you want a string instead of a long you could change the function to AS STRING then return cStr(long_integer) as the return value.  
0
 
rusAuthor Commented:
I have tested it an it's working fine, Thanks!

Best regards
Rudolf Stoum
Trondheim
Norway
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now