From 1e505683cb6df1bccf793880fbc6def1e73359ad Mon Sep 17 00:00:00 2001 From: Rhinemann Date: Tue, 27 Jun 2023 22:28:38 +0300 Subject: [PATCH] Shortened summation code. --- src/bit_utilities.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/bit_utilities.rs b/src/bit_utilities.rs index 1c1a513..78186b8 100644 --- a/src/bit_utilities.rs +++ b/src/bit_utilities.rs @@ -180,18 +180,13 @@ fn binary_sum_with_carry( let mut carry: bool = false; let mut current_bit_sum: u8; - for i in (1..first_term.len()).rev() { + for i in (0..first_term.len()).rev() { current_bit_sum = first_term.memory[i] as u8 + second_term.memory[i] as u8 + carry as u8; carry = u8_to_bool(current_bit_sum & 2); sum.memory[i] = u8_to_bool(current_bit_sum & 1); } - let final_bit_sum: u8 = first_term.memory[0] as u8 + second_term.memory[0] as u8 + carry as u8; - let final_carry: bool = u8_to_bool(final_bit_sum & 2); - - sum.memory[0] = u8_to_bool(final_bit_sum & 1); - - (sum, final_carry) + (sum, carry) } pub fn binary_sum(first_term: &BasicRegister, second_term: &BasicRegister) -> BasicRegister {