Re: [Tutor] how to convert '\xf0' to 0xf0?

2008-12-12 Thread Alan Gauld

What exactly do you want to achieve? I suspect its not what you asked!

To convert the character whose hex value of F0 to an integer value of 
F0

you can use ord() (or just reinterpret the character as a string
using the struct module).


ord('\xf0')

240

To display the hex value of a character as a hex string you can use
string formatting or the hex() function:


c = '\xF0'
0x%x % ord(c)

'0xf0'

0x%X % ord(c)

'0xF0'

hex(ord(c))

'0xf0'

Remember that the representation of a number is always a string.
The value of a number is always binary and can be represented in
any base with the default in Python being decimal.

HTH,


--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how to convert '\xf0' to 0xf0?

2008-12-11 Thread Steve Willoughby

ord('\xf0')
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor