Python Forum
convert hex encoded string to ASCII
Thread Rating:
  • 1 Vote(s) - 4 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert hex encoded string to ASCII
#5
Quote:this why i added the 2nd call to codecs.decode(,"ascii")
You don't need a second call,just add .decode('utf-8').
>>> codecs.decode("707974686f6e2d666f72756d2e696f", "hex").decode('utf-8')
'python-forum.io'
It will work the same in Python 2.x
>>> codecs.decode("707974686f6e2d666f72756d2e696f", "hex").decode('utf-8')
u'python-forum.io'
Strings are Unicode by default in Python 3.x.
>>> u'python-forum.io' == 'python-forum.io'
True
Reply


Messages In This Thread
convert hex encoded string to ASCII - by Skaperen - Sep-29-2016, 07:11 AM
RE: convert hex encoded string to ASCII - by Vexis - Oct-02-2016, 03:02 AM
RE: convert hex encoded string to ASCII - by snippsat - Oct-02-2016, 09:22 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  convert result to hex ascii Jusufs 6 1,565 May-19-2023, 03:21 PM
Last Post: deanhystad
  convert string to float in list jacklee26 6 1,934 Feb-13-2023, 01:14 AM
Last Post: jacklee26
  how to convert tuple value into string mg24 2 2,359 Oct-06-2022, 08:13 AM
Last Post: DeaD_EyE
  Convert string to float problem vasik006 8 3,425 Jun-03-2022, 06:41 PM
Last Post: deanhystad
  Convert a string to a function mikepy 8 2,555 May-13-2022, 07:28 PM
Last Post: mikepy
Question Can you put encoded strings into .txt files? Alivegamer 0 1,264 May-04-2022, 12:50 AM
Last Post: Alivegamer
Question How to convert string to variable? chatguy 5 2,442 Apr-12-2022, 08:31 PM
Last Post: buran
  Convert string to int Frankduc 8 2,496 Feb-13-2022, 04:50 PM
Last Post: menator01
  Convert string to path using Python 2.7 tester_V 10 6,473 Nov-20-2021, 02:20 PM
Last Post: snippsat
  Convert each element of a list to a string for processing tester_V 6 5,362 Jun-16-2021, 02:11 AM
Last Post: tester_V

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020