[TIP] Converting strings to hexadecimal

Shao Sean shaosean at 23am.org
Wed Dec 12 04:08:01 EST 2001


like me, you may be needing to converting simple strings into hex.. after
much research online looking for code to do such said conversion, i came
across a simple function in metatalk "binaryEncode".. it didn't help, but
it's counterpart "binaryDecode" did..

the equal sign "=" in hex is 3D, so the following code allows you to easily
convert this, as well as others:

local vHex
get binaryDecode("H*", "=", vHex)
put toUpper(vHex) into vHex

what does it mean?
H*  means to convert all the characters to the hex, starting with the high
end (make a note, that this is what you want to do, the lowercase 'h*' will
return something different and incorrect)
=  the character(s) to convert
vHex  existing variable (either local or global)

one other note, the results returned from this function will give lowercase
letters ("=" => 3d) instead of the correct uppercase ("=" => 3D).. while
this may seem trivial it does make a difference in some applications (even
though implementations of said applications should handle lowercase as equal
to uppercase)

--
Sean




More information about the Use-livecode mailing list