Shortened summation code.

This commit is contained in:
Rhinemann 2023-06-27 22:28:38 +03:00
parent 289b87a556
commit 1e505683cb
1 changed files with 2 additions and 7 deletions

View File

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