2's complement conversion. Is this right?

Bob Greschke bob at passcal.nmt.edu
Fri Apr 18 20:23:25 EDT 2008


On 2008-04-18 17:55:32 -0600, Ross Ridge 
<rridge at caffeine.csclub.uwaterloo.ca> said:

> George Sakkis  <george.sakkis at gmail.com> wrote:
>> You'd better use a more precise timing method than finger counting,
>> such as timeit. Twice as fast is probably a gross overestimation; on
>> my box (Python 2.5, WinXP) avoiding unpack is around 10% and 40%
>> faster from Ross's and Grant's method, respectively:
> ...
>> def from3Bytes_ross(s):
>> return unpack(">l", s + "\0")[0] >> 8
> 
> If you have Python 2.5, here's a faster version:
> 
> 	from struct import *
> 	unpack_i32be = Struct(">l").unpack
> 
> 	def from3Bytes_ross2(s):
> 	    return unpack_i32be(s + "\0")[0] >> 8
> 
> 					Ross Ridge

That's not even intelligible.  I wanna go back to COBOL. :)




More information about the Python-list mailing list