Add binary multiplication functions #3

Merged
Rhinemann merged 4 commits from multiplication-implementation into master 2023-06-28 14:19:29 +03:00
1 changed files with 2 additions and 6 deletions
Showing only changes of commit 5a26802c34 - Show all commits

View File

@ -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: