On 30.12.16 16:47, Steve D'Aprano wrote:
Again, assume both operands are in range for an N-bit signed integer. What's a good way to efficiently, or at least not too inefficiently, do the calculations in Python?
def to_unsigned(bits, x):
return x & ((1<<bits)-1)
def to_signed(bits, x):
offset = 1<<(bits-1)
return to_unsigned(bits, x + offset) - offset
--
https://mail.python.org/mailman/listinfo/python-list
