FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Python Hex to character





davidv
Hi. In Python, is there a function that converts a hexadecimal representation of a character in ASCII to the actual character?

e.g. 44 61 76 69 64 --> David

Because if there is a function, I'd much rather use it than hard coding an ascii dictionary. However, if there aren't can anybody tell me if...

1. There's an option in the split() function that splits every second character
2. Convert a bin input to ascii/decimal?

Thanks.
lightwate
It's been over a year since I last used python so I'm not really sure. But I think there's a library called binascii? you might want to check that out

http://docs.python.org/library/binascii.html
cgkanchi
Given a string "44 61 76 69 64", you can use a list comprehension combined with the chr and int functions to achieve this.

Code:

>> myhex = "44 61 76 69 64"
>> mystring = ''.join(chr(int(i,16)) for i in myhex.split(' '))
>> print mystring
David


Cheers,
cgkanchi
jajarvin
Code:
char(integer)
--> Returns a string of one character whose ASCII code is the integer

so for example
Code:
char(65)
will return the letter 'A'
Related topics
Monty Python
Favorite Star Wars Character
Python Tutorial
Python
The character of the teleplay "pretender"
Strongman character WIP (3D)
python tutorials
python tutorials
Python beginners help!
Writing to a file -- Python
Python - Using files
A Python Expression Evaluator
Python Expression Evaluator Version 2
Python: Changing a string (Assignment)
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.