Add binary multiplication functions #3
|
@ -127,16 +127,12 @@ def binary_sum_with_carry(first_term: BasicRegister, second_term: BasicRegister)
|
|||
result_term = BasicRegister([False] * len(first_term))
|
||||
|
||||
carry = False
|
||||
for i in range(len(first_term) - 1, 0, -1):
|
||||
for i in range(len(first_term) - 1, -1, -1):
|
||||
current_bit_sum = first_term.memory[i] + second_term.memory[i] + carry
|
||||
carry = bool(current_bit_sum & 2)
|
||||
result_term.memory[i] = bool(current_bit_sum & 1)
|
||||
|
||||
final_bit_sum = first_term.memory[0] + second_term.memory[0] + carry
|
||||
final_carry = bool(final_bit_sum & 2)
|
||||
result_term.memory[0] = bool(final_bit_sum & 1)
|
||||
|
||||
return result_term, final_carry
|
||||
return result_term, carry
|
||||
|
||||
|
||||
def binary_sum(first_term: BasicRegister, second_term: BasicRegister) -> BasicRegister:
|
||||
|
|
Loading…
Reference in New Issue