def _get_int_value(self, message, value): bin_len = self.length.decode_lengths(message)[0] * 8 min = pow(-2, (bin_len - 1)) max = pow(2, (bin_len - 1)) - 1 if not min <= to_int(value) <= max: raise AssertionError('Value %s out of range (%d..%d)' % (value, min, max)) return to_twos_comp(value, bin_len)
def test_to_twos_comp(self): self.assertEquals(184, to_twos_comp("-72", 8)) self.assertEquals(47, to_twos_comp("47", 8)) self.assertEquals(147, to_twos_comp("-109", 8)) self.assertEquals(189, to_twos_comp("-67", 8)) self.assertEquals(81, to_twos_comp("81", 8))