mwalle/osccap

convert does not work in python3

Opened this issue · 0 comments

values = [(((i[0]<<8 + i[1]) - ((i[0]>>7)*0xffff)) * inc + offs) for i in chunks(data,2)] #Python 3 FIXME test formula for correctness

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_byte
0x100+b-0x10000