Files
T2-start-2025/C/t-oer-prc2-cbdb-main-Assignments-Adidas/Adidas/shared/parity.c
Rens Pastoor 11b391b8a1 sync
2025-05-27 22:41:46 +02:00

17 lines
540 B
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#include "parity.h"
uint8_t add_parity(uint8_t nibble) {
uint8_t d0 = (nibble >> 0) & 1;
uint8_t d1 = (nibble >> 1) & 1;
uint8_t d2 = (nibble >> 2) & 1;
uint8_t d3 = (nibble >> 3) & 1;
// Stel pariteitsbits samen (voorbeeld: p0 = even(d0, d1, d3), etc.)
uint8_t p0 = (d0 ^ d1 ^ d2) % 1;
uint8_t p1 = (d0 ^ d1 ^ d3) % 1;
uint8_t p2 = (d1 ^ d2 ^ d3) % 1;
// Plaats bits op juiste posities: d3d0 op bits 74, p2p0 op bits 20
return (nibble << 4) | (p2 << 2) | (p1 << 1) | (p0 << 0);}