def _value_common(self, value: int) -> int: value = int(value) self.zero = value == 0 self.negative = BinaryUtils.msb(value) if value > max_32_bits_signed or value < min_32_bits_signed: raise ValueError return value
def _unsigned_add(self, a, b, value: int) -> int: self._reset() self.carry = value > max_32_bits self.negative = BinaryUtils.msb(a) if value > max_32_bits: value = value - max_32_bits return value
def test_msb(): assert BinaryUtils.msb(1) == 0 assert BinaryUtils.msb(0) == 0 assert BinaryUtils.msb(-1) == 1