# Algorithm to convert text to hex



## vmars316 (Oct 24, 2010)

Greetings,
I am in need of an Algorithm to convert text to hex. 
For instance: Hello World! = 48 65 6C 6C 6F 1 57 6F 72 6C 64 21 

Or perhaps there is a .dll for this? 
Or a routine written in Assembler language. 

Thanks a bunch...vmars316


----------



## Ent (Apr 11, 2009)

What language are you dealing with? Most languages would have the capacity to 

Run through each character in a string
Take the ASCII value for the selected character.
Display the number in hexidecimal
Go to the next number


----------



## lotuseclat79 (Sep 12, 2003)

Hi vmars316,

The easiest way to solve this problem is to scan the character and format the output for it in hex format. It can be as easy as char(%x, getchar(c)) in a for loop until the end of input. Experiment with it. C language is simple at this.

-- Tom


----------



## benzrf (Feb 26, 2009)

You'll have to say what language; people can't really help otherwise. The above code wouldn't work in BASIC, for example...


----------



## Ent (Apr 11, 2009)

By the way in your example you report the space as 1, not as the ascii value of 32 (ox20). Is there a particular reason for this?


----------



## vmars316 (Oct 24, 2010)

Hey, Thanks All,
I ended up doing this in HotBasic:

'=====str2hex2.bas
$APPTYPE CONSOLE: $TYPECHECK ON
defint i,j 'scratch variables
defstr a$="Hello World!"
defstr r$,s$
for i=1 to a$.length
j=asc(a$_)
s$=mid$(hex$(j),7)
r$.append s$,space
next i
print r$
PAUSE
END
'=====str2hex2.bas

vmars316_


----------

