From 0f94f6d37a34d20fb9f06d925173c066e7ef89bf Mon Sep 17 00:00:00 2001 From: Rhinemann Date: Tue, 27 Jun 2023 16:43:18 +0300 Subject: [PATCH] Minor rewrites. --- bitutilities.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/bitutilities.py b/bitutilities.py index b976937..079e660 100644 --- a/bitutilities.py +++ b/bitutilities.py @@ -97,7 +97,8 @@ def binary_sum(first_term: BasicRegister, second_term: BasicRegister, return_rem return result -def binary_subtraction_1_complement(first_term: BasicRegister, second_term: BasicRegister) -> BasicRegister: +def binary_subtraction(first_term: BasicRegister, second_term: BasicRegister) -> BasicRegister: + second_term.reverse() result: BasicRegister @@ -105,7 +106,7 @@ def binary_subtraction_1_complement(first_term: BasicRegister, second_term: Basi result, final_carry = binary_sum(first_term, second_term, True) if final_carry: - return binary_sum(result, BasicRegister([True])) + return binary_sum(result, BasicRegister([True] * len(result))) else: result.reverse() return result @@ -113,16 +114,12 @@ def binary_subtraction_1_complement(first_term: BasicRegister, second_term: Basi def align_registers(first_register: BasicRegister, second_register: BasicRegister) \ -> tuple[BasicRegister, BasicRegister]: - size_a = len(first_register) - size_b = len(second_register) + first_size = len(first_register) + second_size = len(second_register) - required_size = max(size_a, size_b) + required_size = max(first_size, second_size) - a = first_register - b = second_register - - if size_a != size_b: - a = a.adjusted_by_size(required_size) - b = b.adjusted_by_size(required_size) - - return a, b + if first_size != second_size: + return first_register.adjusted_by_size(required_size), second_register.adjusted_by_size(required_size) + else: + return first_register, second_register