PDA

View Full Version : Convert String To Hex



Angelika
07-29-2002, 09:24 AM
Hello!

How can I convert a string into the hex value (A into 41)??

Thank you.

Keppler
07-29-2002, 09:45 AM
You didn't specify any preferred method, so can I point you to the VBScript Hex Function
http://www.devguru.com/Technologies/vbscript/quickref/hex.html

ixHex = Hex(Asc("A"))

Angelika
07-30-2002, 12:45 AM
thanks for your answer.

Is there a method to convert the string to hex in InstallScript?

Keppler
07-30-2002, 04:29 AM
not that I'm aware of.

Duncan
07-30-2002, 07:48 AM
You may use this piece of code :

Sprintf(szHexa,"%lX",szCar[i]);

...where :
'szCar' is the string containing the character you want the hexadecimal value from.
'i' is the position of this character in szCar (0 for the first one).
'szHexa' is the resulting string which will then contain the hexadecimal value.

This may come a bit late, but it could be interesting for the record...

Angelika
07-30-2002, 07:59 AM
Thank you!!

This is exactely what I searched for and it did not came too late :-)

Keppler
07-30-2002, 08:01 AM
ah yes.. had I been prepared to think for a while.. :)

Thanks Thomas, the record is duly updated..

Duncan
07-30-2002, 08:11 AM
You're welcome :)

By the way, this works because InstallScript deals with characters as if it were numbers: with their value. So when you write "szCar[i]", you get the value of the i-th character. And %lX with Sprintf represents the hexadecimal writing of a number (uppercase. Use %lx for lowercase writing).

Of course, if you already have your character as a character type element, you may use it directly, without casting it to a string before. ( Sprintf(szHexa,"%lX",cCar); )

Regards,