From 522236e20c952786ff9d0a0f7010843c6b3fd2fd Mon Sep 17 00:00:00 2001 From: Priec Date: Sun, 23 Nov 2025 23:12:32 +0100 Subject: [PATCH] removed redundant code --- .../software_uart/src/uart_emulation.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/semestralka_1_final_crate/software_uart/src/uart_emulation.rs b/semestralka_1_final_crate/software_uart/src/uart_emulation.rs index 7875b38..56992f0 100644 --- a/semestralka_1_final_crate/software_uart/src/uart_emulation.rs +++ b/semestralka_1_final_crate/software_uart/src/uart_emulation.rs @@ -196,10 +196,7 @@ fn calculate_parity(data: u8, parity: Parity, data_bits: u8) -> u8 { match parity { Parity::None => 0, Parity::Even | Parity::Odd => { - // Mask to only count bits that are part of the data - let mask: u8 = if data_bits == 8 { 0xFF } else { ((1u16 << data_bits) - 1) as u8 }; - - let ones = (data & mask).count_ones() & 1; + let ones = data.count_ones() & 1; match parity { Parity::Even => ones as u8, // If ones=1 (odd), emit 1 to make even Parity::Odd => (ones ^ 1) as u8, // XOR - If ones=1 (odd), emit 0 to keep odd