char string 2 hex string



Hello!

I need to transform a string from a file into a hexadecimal
representation, for example:

"AAA" should be "414141"

With perl I do this with:

unpack("H*","AAA")

And with python I got this:

"".join([str(hex(ord(x)))[2:] for x in "AAA"])

But seems a little "weird" for me.

Is there another way?
Thanks in advance!
.



Relevant Pages

  • Re: dictionary/hash and 1 versus 1
    ... In order to keep things simple, Perl's string operators ... programming language you have to use its idioms or you end up fighting ... IMO, since Python is strongly but dynamically typed, a) is the 'worst' ... Perl and Python. ...
    (comp.lang.python)
  • Re: strings with formatted characters in %ARGV
    ... strings to a perl program and have them print with the formatting. ... special characters when used from the command line? ... this into the text FOO followed by three newlines in whatever representation ... I could see this in the case of variables in a string -- how would ...
    (comp.lang.perl.misc)
  • Re: why cl packages are hard to use ?
    ... | type used to represent code in Python is the string, ... Scheme programs are ... uniform representation is the susceptibility ...
    (comp.lang.lisp)
  • Re: A way of checking if a string contains a number
    ... I'm new to python, but I have used a fair bit of C and Perl ... All I am trying to do is detect if there is a number in a string. ... regularExpressionCheck = doesHaveNumber.search ...
    (comp.lang.python)
  • A way of checking if a string contains a number
    ... I'm new to python, but I have used a fair bit of C and Perl ... All I am trying to do is detect if there is a number in a string. ... regularExpressionCheck = doesHaveNumber.search ...
    (comp.lang.python)