How to convert a number to hex number?

Bengt Richter bokr at oz.net
Tue Nov 8 17:35:45 EST 2005


On 08 Nov 2005 08:07:34 -0800, Paul Rubin <http://phr.cx@NOSPAM.invalid> wrote:

>"dcrespo" <dcrespo at gmail.com> writes:
>> >>>hex(255)[2:]
>> 'ff'
>
>'%x'%255 is preferable since the format of hex() output can vary.  Try hex(33**33).

Not to mention (#@%*!-pletive deleted ;-)

 >>> hex(-255)[2:]
 'xff'
 >>> hex(-255)
 '-0xff'
 >>> hex(-255&0xff)
 '0x1'

Regards,
Bengt Richter



More information about the Python-list mailing list