简体   繁体   中英

How do I convert hexadecimal string to text

How do I convert hexadecimal strings to text in Python?

I have got a hexadecimal string

0x3C503E3235206D4C206F662033204D2048436C207765726520616464656420746F203735206D4C206F6620302E3035204D2048436C2E20546865206D6F6C6172697479206F662048436C20696E2074686520726573756C74696E6720736F6C7574696F6E20202026656D73703B26656D73703B26656D73703B26656D73703B2020200D0A20202026656D73703B26656D73703B26656D73703B26656D73703B2020697320617070726F78696D6174656C792D

and I want to convert it into text with help of Python. How can I do it?

I have tried this

print(bytes.fromhex(xyz))

where xyz is my variable in which this string is stored but I get this error

non-hexadecimal number found in fromhex() arg at position 1

Just slice the '0x' characters from the beginning of your string. So

print(bytes.fromhex(var[2:]))

Will give

b'<P>25 mL of 3 M HCl were added to 75 mL of 0.05 M HCl. The molarity of HCl in the resulting solution   &emsp;&emsp;&emsp;&emsp;   \r\n   &emsp;&emsp;&emsp;&emsp;  is approximately-'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM