Prev: Turbogears 2 training this weekend in Washington, DC USA
Next: How to measure speed improvements across revisions over time?
From: Anthony Cole on 10 May 2010 15:55 How can I concatenate 2 hex strings (e.g. '\x16' and '\xb9') then convert the answer to an integer? When I try i always end up with the ASCII equivalent! Thanks, Anthony
From: MRAB on 10 May 2010 16:15 Anthony Cole wrote: > How can I concatenate 2 hex strings (e.g. '\x16' and '\xb9') then convert > the answer to an integer? > > When I try i always end up with the ASCII equivalent! > Those are just bytestrings (assuming you're using Python 2.x), ie strings using 1 byte per character. You can convert a bytestring to an integer using the functions in the 'struct' module.
From: Chris Rebert on 10 May 2010 16:15
On Mon, May 10, 2010 at 12:55 PM, Anthony Cole <anthony.cole(a)gmail.com> wrote: > How can I concatenate 2 hex strings (e.g. '\x16' and '\xb9') then convert > the answer to an integer? > > When I try i always end up with the ASCII equivalent! I think you want the `struct` module: struct â Interpret strings as packed binary data http://docs.python.org/library/struct.html Cheers, Chris -- http://blog.rebertia.com |