problem with bcd and a number

Peter Otten __peter__ at web.de
Fri Aug 5 17:52:38 CEST 2011


Chris Angelico wrote:

> On Fri, Aug 5, 2011 at 1:40 AM, Dan Stromberg <drsalists at gmail.com> wrote:
>>>>> print int(hex(0x72).replace('0x', ''))
>> 72
> 
> Or simpler: int(hex(0x72)[2:])
> 
> Although if you have it as a string, you need to ord() the string.

Or use str.encode():

>>> int("\x72".encode("hex"))
72
>>> int("\x12\x34\x56".encode("hex"))
123456

> It's probably better to just do the bitwise operations though.





More information about the Python-list mailing list