Convert hex to string

J

Java and Swing

I have some output stored in a string that looks like..
'\x01\xee\x1eo\xc3+\x8b\x83\xfad\xf6E\xaa\x0ea/I\x96\x83\xf5G\xa3\rQ\xfcH\xee\r'


According to, http://docs.python.org/lib/typesseq-strings.html, this is
"Unsigned Hexidecimal (lowercase)". How can I get this into normal
Ascii so that I can read it?

thanks.
 
J

jepler

it *is* a string.

because most of the characters are not printable, they're presented using hex
notation when you repr() the string. That's what entering an expression in the
interactive interpreter does (except that it never prints 'None').

If you really want to write whatever those bytes are, then do something like
Jeff

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD4DBQFDQZT8Jd01MZaTXX0RAm4QAJ9QKsJlGbPpSkChLPQfKvbMUdS4QQCYuMuK
vcQ5hyK6Vj62SFDHS/gKQA==
=7AYM
-----END PGP SIGNATURE-----
 
L

Larry Bates

It contains non-printing and non-ASCII characters so it can't be
printed lie you want. The best Python can do is to show you
the hexadecimal of those bytes (as it has done). Printable ASCII
characters lie in the range 32 decimal (20 hex) to 125 decimal
(7F hex). Those characters in that range are shown properly.

Example: There is no printable ASCII character for the first
character which is \x01. My ASCII table shows that this
character represents an ASCII SOH (start of heading) character.

-Larry Bates
 
M

Magnus Lycka

Java said:
I have some output stored in a string that looks like..



'\x01\xee\x1eo\xc3+\x8b\x83\xfad\xf6E\xaa\x0ea/I\x96\x83\xf5G\xa3\rQ\xfcH\xee\r'


According to, http://docs.python.org/lib/typesseq-strings.html, this is
"Unsigned Hexidecimal (lowercase)". How can I get this into normal
Ascii so that I can read it?

What did you expect this string to print? Where did it come from?
Viewed as ASCII it's mainly non-printables, with o, +, d, E, a/I,
G, Q and H stuffed in, but I'm pretty sure it isn't 8 bit text
in any normal encoding. The only reason to suspect that this might
be text after all, is that it ends with a carriage return.

Converting your string to numbers, we get...
1 238 30 111(o) 195 43(+) 139 131 250 100(d) 246 69(E) 170 14 97(a)
47(/) 73(I) 150 131 245 71(G) 163 13 81 (Q) 252 72(H) 238 13.

You can find the definition of ASCII via Google.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top