Leo M. Cabrera wrote:
Sam Roberts wrote:
On Thu, Mar 22, 2007 at 08:29:00PM -0400, L-28C wrote:
PS: The hex number is in string (character) format. Sorry about that.
string.sub() to get rid of the leading "0x"?
No; I meant the character itself, not the '0x13' string
representation. The 13th ASCII character, device control 3. It's
printing that instead of the number '13'.
Get what I'm saying? Thanks.
I got a question. Given a hexadecimal number (ie. 0x13), how can I
convert that to the string "13"? I use print() and it gives me a
random ASCII character.
-- Convert a hexadecimal string to a number ("13" -> 19, "FF" -> 255)
n = tonumber( "13", 16 )
-- Convert a ASCII code (number) to a char (13 -> "\r", 10 -> "\n")
c = string.char( n )
-- Convert a char to it's ASCII code ("\r" -> 13, "\n" -> 10 )
print( string.byte( c ) )
> I use print() and it gives me a random ASCII character
Random?
--rb