On 05/28/2013 05:41 AM, silusilus...@gmail.com wrote:
Thanks for your reply: very useful!!
I have another question: with hex command i display (for example)

0x1

is it possible to display 0x01?

hex() is a function, not a command. And it only takes the one parameter, the int to be converted.

For more generality, try the str.format() method. The x type converts to hex without any prefix, and then you can add the width and fill field.

http://docs.python.org/2/library/stdtypes.html#str.format
http://docs.python.org/2/library/string.html#formatstrings
http://docs.python.org/2/library/string.html#format-specification-mini-language

For starters, try:

print "0x{0:0>2x}".format(12)
or
print "0x{0:0>2X}".format(12)
    if you like uppercase hex characters

--
DaveA
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to