WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Number Conversion

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

How to Convert a Hex String to Char

Keywords: 	 hex decimal ascii num2char

Question:

How can I convert a hex string to char ?
ex: x'41' = "A"

Answer:

origstring="x'4a'"
hexstring=origstring
;remove x's and single quotes
hexstring=StrReplace(hexstring,"x","")
hexstring=StrReplace(hexstring,"'","")
;force to two digits
hexstring=strfix(hexstring,"0",2)
h1=strsub(hexstring,1,1)
h2=strsub(hexstring,2,1)
h1=StrIndexnc("123456789abcdef",h1,0,@fwdscan)
h2=StrIndexnc("123456789abcdef",h2,0,@fwdscan)
DaNum=h1*16+h2
DaChar=Num2Char(DaNum)
Message(origstring,DaChar)
or by using the WILX extender, avoid some messy math
AddExtender("wilx34i.dll")
origstring="x'4a'"
hexstring=origstring
;remove x's and single quotes
hexstring=StrReplace(hexstring,"x","")
hexstring=StrReplace(hexstring,"'","")
DaNum=xhex(hexstring)
DaChar=Num2Char(DaNum)
Message(origstring,DaChar)

Article ID:   W14658
Filename:   How to Convert a Hex String to Char.txt
File Created: 2001:01:24:16:14:38
Last Updated: 2001:01:24:16:14:38