How to convert a number to hex number?

Bengt Richter bokr at
Tue Nov 8 23:35:45 CET 2005

On 08 Nov 2005 08:07:34 -0800, Paul Rubin <> wrote:

>"dcrespo" <dcrespo at> 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:]
 >>> hex(-255)
 >>> hex(-255&0xff)

Bengt Richter

More information about the Python-list mailing list