convert does not work in python3
Opened this issue · 0 comments
jbaltes commented
Line 56 in efec4ee
need to calculate twos complement:
((255<<8)+255)-0x10000 * 1 = -1
smallest negative number: ((128<<8)+0)-0x10000 * 1 = -32768
biggest positive number: ((127<<8)+255)-0x10000 * 0 = 32767
addtitional parentheses needed
timeit.Timer('a=255;b=255;((a<<8)+b)-0x10000*(a<<7)', 'gc.enable()').timeit()
0.2427769000059925
timeit.Timer("a=255;b=255;int(format(a,'08b')+format(b,'08b'),2)", 'gc.enable()').timeit()
1.5376816670177504
words_to_int(high_byte, low_byte):
if high_byte < 128:
high_byte0x100+b
else:
high_byte0x100+b-0x10000