Solved

hexidecimal conversion

Posted on 2004-03-24
7
580 Views
Last Modified: 2012-08-13
I have a text file that is all in hexidecimal. I need a code in vb 6 that will convert the hexidecimal into characters, How can I do this

0
Comment
Question by:bear23
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 

Accepted Solution

by:
aioakeim earned 50 total points
ID: 10669419
try something like this
i think it will hepl u
function hextochr(strsms)

Dec2Chr = ""
Hex2Dec = 0

for j=1 to len(strsms)
      InputData = Mid(strsms,j,2)
      j=j+1
      HexStep = 0
      DecOut = 0

      select case InputData
            case "13"            Dec2Chr = Dec2Chr & "Γ"
            case "10"            Dec2Chr = Dec2Chr & "Δ"
            case "19"            Dec2Chr = Dec2Chr & "Θ"
            case "1A"            Dec2Chr = Dec2Chr & "Ξ"
            case "14"            Dec2Chr = Dec2Chr & "Λ"
            case "16"            Dec2Chr = Dec2Chr & "Π"
            case "18"            Dec2Chr = Dec2Chr & "Σ"
            case "12"            Dec2Chr = Dec2Chr & "Φ"
            case "17"            Dec2Chr = Dec2Chr & "Ψ"
            case "15"            Dec2Chr = Dec2Chr & "Ω"
            case "41","61"      Dec2Chr = Dec2Chr & "Α"
            case "42","62"      Dec2Chr = Dec2Chr & "Β"
            case "45","65"      Dec2Chr = Dec2Chr & "Ε"
            case "48","68"      Dec2Chr = Dec2Chr & "Η"
            case "49","69"      Dec2Chr = Dec2Chr & "Ι"
            case "4B","6B"      Dec2Chr = Dec2Chr & "Κ"
            case "4D","6D"      Dec2Chr = Dec2Chr & "Μ"
            case "4E","6E"      Dec2Chr = Dec2Chr & "Ν"
            case "4F","6F"      Dec2Chr = Dec2Chr & "Ο"
            case "50","70"      Dec2Chr = Dec2Chr & "Ρ"
            case "54","74"      Dec2Chr = Dec2Chr & "Τ"
            case "58","78"      Dec2Chr = Dec2Chr & "Χ"
            case "59","79"      Dec2Chr = Dec2Chr & "Υ"
            case "5A","7A"      Dec2Chr = Dec2Chr & "Ζ"
            case "55","75"      Dec2Chr = Dec2Chr & "U"
            case "47","67"      Dec2Chr = Dec2Chr & "G"
            case "43","63"      Dec2Chr = Dec2Chr & "C"
            case "4C","6C"      Dec2Chr = Dec2Chr & "L"
            case "44","64"      Dec2Chr = Dec2Chr & "D"
            case "46","66"      Dec2Chr = Dec2Chr & "F"
            case "4A","6A"      Dec2Chr = Dec2Chr & "J"
            case "51","71"      Dec2Chr = Dec2Chr & "Q"
            case "52","72"      Dec2Chr = Dec2Chr & "R"
            case "53","73"      Dec2Chr = Dec2Chr & "S"
            case "56","76"      Dec2Chr = Dec2Chr & "V"
            case "57","77"      Dec2Chr = Dec2Chr & "W"
            case "20"            Dec2Chr = Dec2Chr & " "
            case "3A"            Dec2Chr = Dec2Chr & ":"
            case "2E"            Dec2Chr = Dec2Chr & "."
            case "30"            Dec2Chr = Dec2Chr & "0"
            case "31"            Dec2Chr = Dec2Chr & "1"
            case "32"            Dec2Chr = Dec2Chr & "2"
            case "33"            Dec2Chr = Dec2Chr & "3"
            case "34"            Dec2Chr = Dec2Chr & "4"
            case "35"            Dec2Chr = Dec2Chr & "5"
            case "36"            Dec2Chr = Dec2Chr & "6"
            case "37"            Dec2Chr = Dec2Chr & "7"
            case "38"            Dec2Chr = Dec2Chr & "8"
            case "39"            Dec2Chr = Dec2Chr & "9"


      end select
next
      hextochr = ""
      hextochr = Dec2Chr

End function
0
 

Expert Comment

by:aioakeim
ID: 10669430
these strande characters (like "Γ") are greek dont be confused
0
 

Author Comment

by:bear23
ID: 10670641
the text file looks like this:
sample, alot more to it:
C8001FF0F8C4C3F1F0F4F0F3F2F3E5D5C6D3D6
C4001FC9D5F7F1F1F0F0F0F0F6404040404040

how could I turn this into characters. I tired your code but nothing happened
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 24

Expert Comment

by:SunBow
ID: 10672800
homework?
The conversion should go from numeric to alpha using the chr() function
But first you need the number, which you do not have.
You need to read in the hex pairs, remembering that the first character read in represents a multiple of 16.
I prefer doing it in additive math, adding the decimal equivalent of first number to the base (such as 65)

But it can be done well enough with a case, like the above, for changing 0-f to 0-15, multiply by 16, add the next number and convert
0
 

Author Comment

by:bear23
ID: 10677164
no it is not homework. I have a hex file like I listed above and need to find a way to convert it into characters & numbers.

ANother words be able to read it.....
0
 
LVL 1

Expert Comment

by:dcrysler
ID: 10677892
SubBow has it right, I just thought I'd add this in case it wasn't clear.   The valid values for hex are 0-9 and A-F (these represent 10-15)  Hexadecimal values are in pairs, so your test data above breaks down to

C8 00 1F F0 F8....

C=12
8=8
thus the decimal value = (12*16) + 8 = 200

so your test data then converts to

200 0 31 240 248 .....

You can then compare the decimal values to the ascii table (www.asciitable.com) to convert from decimal to text.  Of course you don't have to do this manually,  as noted above the chr() function will do if for you.  This is, assuming the data was encoded as ascii text.  Unicode uses two bytes per character....
0
 
LVL 24

Expert Comment

by:SunBow
ID: 10690390
Done?
What was the answer?
0

Featured Post

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Progress

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question